AngularjS美元注入器:unpr

AngularjS $injector:unpr

本文关键字:unpr 注入器 美元 AngularjS      更新时间:2023-09-26

我有以下控制器:

/** Calculation controller **/
app.controller('calculationController', ['$scope','$modal','content', function($scope, $modal, content) {
    /** data recieved from get request **/
    $scope.data = content.data; //promise
    /** function to edit data **/
    $scope.edit = function(item){
        var htmlContents = {
            title: 'Edit product',
            body: 'Please confirm that you want to edit the product'
        }
        var modalInstance = $modal.open({
            templateUrl : templateBase + 'views/modal/dialog.html',
            controller : 'modalInstanceController',
            resolve : {
                items : function() { return item; },
                html : function() { return htmlContents; }
            }
        });
    }
    /** function to delete data **/
    $scope.trash = function(item){
    }
}]);
app.controller('modalInstanceController', ['$scope', '$modalInstance','items','html', function($scope,$modalInstance,items,html) {
    $scope.title = html.title;
    $scope.body  = html.body;
}]);

我想要完成的是打开一个对话框的内容从'dialog.html'但是一旦我点击:

<img ng-src="images/icn_edit.png" ng-click="edit(item)" alt="Edit">

$injector:unpr出现在控制台日志中

dialog.html的内容如下:

<div ng-controller="modalInstanceController">
<div class="modal-header">
    <h3>{{title}}</h3>
</div>
<div class="modal-body">
    {{body}}
</div>
<div class="modal-footer">
    <button class="btn btn-primary" ng-click="ok()">OK</button>
    <button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>

我知道我错过了注入的东西,但经过几个小时的查看代码,我无法找到什么…

从我可以观察到'$scope', '$modalInstance','items','html'被注入到modelInstanceController..

感谢您的帮助。

谢谢

从你的dialog.html中删除

Ng-controller="modalInstanceController"

应该是普通的div,这样就可以了

dialog.html的html标记应该像这样:

<div>
<div class="modal-header">
    <h3>{{title}}</h3>
</div>
<div class="modal-body">
    {{body}}
</div>
<div class="modal-footer">
    <button class="btn btn-primary" ng-click="ok()">OK</button>
    <button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>