我在HTML中的脚本标签中编写了一个控制器。当我运行代码时,代码执行直到依赖注入,但不执行回调函数。
当我在其他应用程序上成功运行类似的代码时,我无法弄清楚这有什么问题。
此外,如果我显式调用回调函数,则不会识别注入的依赖项。
<script type="text/javascript">
angular.module('DesignPortal.layout', [])
.controller('NgLayoutController', NgLayoutController);
NgLayoutController.$inject = ['$scope'];
function NgLayoutController($scope) {
var loggedUserId = dpConfig.userInfo.id;
}
</script>
如果明确调用该函数,则无法识别上面注入的范围。
答案 0 :(得分:0)
试试这个。我没有尝试过自己,但它应该有用。
<script type="text/javascript">
angular.module('DesignPortal.layout', [])
.controller('NgLayoutController',['$scope', function($scope) {
function NgLayoutController() {
var loggedUserId = dpConfig.userInfo.id;
}
}]);
</script>