gpt4 book ai didi

javascript - AngularjS $注入(inject)器:unpr

转载 作者:行者123 更新时间:2023-12-03 12:13:26 26 4
gpt4 key购买 nike

我有以下 Controller :

/** 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>

我知道我错过了注入(inject)一些东西,但是经过几个小时的查看代码后我无法找到什么......

据我观察,'$scope'、'$modalInstance'、'items'、'html' 被注入(inject) 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>

关于javascript - AngularjS $注入(inject)器:unpr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24844385/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com