我说两个模块:
foo.afoo.b和一个应用程序模块:
angular.module("foo", ["foo.a","foo.b"])
Run Code Online (Sandbox Code Playgroud)
我在模块中有一项服务foo.b说:
angular.module("foo.b", [])
angular.module("foo.b").factory("helper",helperFn);
Run Code Online (Sandbox Code Playgroud)
我想在我的一个控制器中使用它foo.a.
我所做的是简单的依赖注入:
angular.module("foo.a", []);
angular.module("foo.a")
.controller("MyController",["helper",MyControllerFn]);
Run Code Online (Sandbox Code Playgroud)
这是有效的.
我的问题是
foo.b即使它没有被声明为模块a的依赖项?在我的本地计算机上,我一直使用--disable-web-security --user-data-dir来禁用Web安全性.升级到Chrome版本66后,我已开始通过...警告接收跨站点文档阻止当前来源.如何禁用此版本的Chrome的Web安全性?
我写了一个指令,它有助于在ajax请求挂起时禁用按钮.
这是我的指示:
.directive('requestPending', ['$http', function ($http) {
return {
restrict: 'A',
scope: {
'requestPending': '='
},
link: function (scope, el, attr) {
scope.$watch(function () {
return $http.pendingRequests.length;
}, function (requests) {
scope.requestPending = requests > 0;
})
}
}
}])
Run Code Online (Sandbox Code Playgroud)
HTML就像:
<button request-pending="pending" ng-disabled="pending">Save</button>
Run Code Online (Sandbox Code Playgroud)
想知道这是否是一种正确的做法.我想不要使用$ watch
谢谢.