错误:参数'ModalDemoCtrl'不是函数,没有定义
Error: Argument 'ModalDemoCtrl' is not a function, got undefined
嗨,当我在我的项目中使用angularJS时,我得到了上述错误。我使用django框架为我的整个项目。所以我没有任何额外的js文件为我的项目。以下是我的代码。
JS:
{{ ngapp }}.controller("ModalDemoCtrl", function ($scope, $http, $cookies, $resource, $log, $modal) {
$scope.items = ['item1', 'item2', 'item3'];
$scope.animationsEnabled = true;
$scope.open = function (size) {
var modalInstance = $modal.open({
animation: $scope.animationsEnabled,
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: size,
resolve: {
items: function () {
return $scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
$scope.toggleAnimation = function () {
$scope.animationsEnabled = !$scope.animationsEnabled;
};
});
// Please note that $modalInstance represents a modal window (instance) dependency.
// It is not the same as the $modal service used above.
{{ngapp}}.controller('ModalInstanceCtrl', function ($scope, $modalInstance, items) {
$scope.items = items;
$scope.selected = {
item: $scope.items[0]
};
$scope.ok = function () {
$modalInstance.close($scope.selected.item);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
});
和我的html的一部分(它太长了,这就是为什么):
<div class="well" ng-controller="ModalDemoCtrl">
<script type="text/ng-template" id="enable.html">
</script>
<button type="button" class="btn btn-info" ng-click="open('lg')">blahh</button>  </div>
谁能告诉我这里出了什么问题?我已经想了很长时间了。我不知道如何处理这个问题。
依赖关系应该被推断出来,但也许可以尝试注入$scope和其他类似的。
controller("ModalDemoCtrl", ['$scope','$http','$cookies', '$resource', '$log', '$modal', function ($scope, $http, $cookies, $resource, $log, $modal) {
...
}]);
相关文章:
- 用嵌套函数和默认函数定义函数
- 自定义函数中的光标位置
- Jquery未定义函数正在停止其他操作
- 在不破坏未定义函数的情况下,对多个视图使用单个js文件
- javascript无法重新定义函数内部的全局对象
- 定义函数时,如何捕获外部变量的当前值
- 能够在定义函数表达式之前使用它
- Google Sheet自定义函数返回0
- Javascript-defineProperty和直接在对象上定义函数之间的区别
- 其中是自定义函数中的属性
- 创建自定义函数以在函数上运行完整的多选下拉列表
- Google Sheets自定义函数条件格式
- 为什么当我需要位于顶部的函数时,在脚本中的某些点上没有定义函数
- 使用变量的名称,然后为该变量定义函数
- dalek回调或自定义函数
- 如何在angular ui模态控制器中定义函数
- Uncaught ReferenceError:尝试在Android网络视图中访问时未定义函数
- UI网格:如何从自定义函数访问MODEL_COL_FIELD
- 在构造函数中定义函数会比将其附加到原型消耗更多的内存
- 使用 Javascript 中的函数重新定义函数