在 60 分钟内跟随 AngularJS 我正在尝试将工厂添加到当前代码中。
我有 lineman angular 应用程序,其中 angular 声明如下:
angular.module("app", ["ngResource", "ngRoute"]).run(function($rootScope) {
// adds some basic utilities to the $rootScope for debugging purposes
$rootScope.log = function(thing) {
console.log(thing);
};
});
我想添加以下代码但遇到 JS 语法问题
.factory('simpleFactory', function () {
var factory = {};
var customers = [];
factory.getCustomers = function () {
return customers;
};
return factory;
}
合并这两个块的正确语法是什么?我还应该模仿控制器目录来创建工厂还是应该真正添加到第一个块中?谢谢