AngularJS-无法在模式调用时实例化控制器
我正在尝试使用ui引导模式在AngularJS中进行CRUD操作 我想我没有意识到设置控制器的继承,每次我试图打开一个模式并调用子控制器时,我都会遇到一个错误:AngularJS-无法在模式调用时实例化控制器,angularjs,twitter-bootstrap,crud,Angularjs,Twitter Bootstrap,Crud,我正在尝试使用ui引导模式在AngularJS中进行CRUD操作 我想我没有意识到设置控制器的继承,每次我试图打开一个模式并调用子控制器时,我都会遇到一个错误: 错误:[$injector:unpr]未知提供程序:$modalInstanceProvider只需从子视图中删除ng控制器指令。替换此行: <div class="modal-content" ng-controller="ChildCtrl"> 到 //在此处包含子视图。 您的代码应该如下所示: <di
错误:[$injector:unpr]未知提供程序:$modalInstanceProvider只需从子视图中删除ng控制器指令。替换此行:
<div class="modal-content" ng-controller="ChildCtrl">
到
//在此处包含子视图。
您的代码应该如下所示:
<div ng-controller="ParentCtrl">
<div>
stuff to handle items.
</div>
/* here your html correspond to parent controller end */
/*include child template here*/
<script type="text/ng-template" id="delete.html">
//include modal popup html code here.
<div class="modal-content" >
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" ng-click="close()" >
<span aria-hidden="true">×</span><span class="sr-only">Close</span>
</button>
<h4>Delete</h4>
</div>
<form name="deleteForm" ng-submit="delete()">
<div class="modal-body">
some info about the model here
</div>
<div class="modal-footer">
<input class="btn" value="Delete" type="submit"/>
</div>
</form>
</div>
</script>
</div>
处理物品的东西。
/*这里您的html对应于父控制器端*/
/*在此处包含子模板*/
//包括模态弹出html代码在这里。
&时代;接近
删除
这里有一些关于模型的信息
我是否应该像示例中那样添加脚本标记?我不知道我是否必须这样做或在那里包含视图的代码。我在上面的回答中添加了更多信息。谢谢,我会尝试告诉你它是如何进行的。
myApp.controller('ParentCtrl', ['$scope', '$modal', function ($scope, $modal) {
//some stuff here
$scope.delete = function (item, size) {
$scope.modalInstance = $modal.open({
templateUrl: 'views/delete.html',
controller: 'ChildCtrl',
size: size,
resolve: {
item : function () {
return item
}
}
});
};
//some stuff here
}]);
myApp.controller('ChildCtrl', ['$scope','$modalInstance', 'item', 'ItemService', function ($scope, $modalInstance, item, ItemService) {
$scope.delete = function () {
ItemService.delete({ id: item.id }, function () {
$modalInstance.close();
$scope.$emit('itemUpdate');
})
};
}]);
<div class="modal-content" ng-controller="ChildCtrl">
<div class="modal-content" >
<script type="text/ng-template" id="delete.html">
//include child view here.
</script>
<div ng-controller="ParentCtrl">
<div>
stuff to handle items.
</div>
/* here your html correspond to parent controller end */
/*include child template here*/
<script type="text/ng-template" id="delete.html">
//include modal popup html code here.
<div class="modal-content" >
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" ng-click="close()" >
<span aria-hidden="true">×</span><span class="sr-only">Close</span>
</button>
<h4>Delete</h4>
</div>
<form name="deleteForm" ng-submit="delete()">
<div class="modal-body">
some info about the model here
</div>
<div class="modal-footer">
<input class="btn" value="Delete" type="submit"/>
</div>
</form>
</div>
</script>
</div>