我试图执行下面有角度js代码的函数。
function updateData() {
var crudApp = angular.module("crudTest", []);
crudApp.service("editData", function() {
var editArray = ["BLAUS", "Blauer See Delikatessen", "Hanna Moos", "Sales Representative", "Forsterstr. 57", "Mannheim", ""];
return {
editArrayy : editArray
};
});
crudApp.controller = ("modalContent",
function($scope) {
$scope.inputs = editData.editArrayy;
});
}
然而错误如下:
未捕捉错误:[$ injector:modulerr] http://errors.angularjs.org/1.3.8/ $ injector / modulerr?p0 = crudTest& p1 =错误%3 ... ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.8%2Fangular.min。 JS%3A17%3A350)
html结构是:
<html ng-app="crudTest">
<body>
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Edit Customer</h4>
</div>
<div class="modal-body" ng-controller="modalContent">
<form ng-repeat="input in inputs">
<span>Customer ID</span>
<input type="text" value={{input}} />
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Close
</button>
<button type="button" class="btn btn-primary">
Save changes
</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
</html>
答案 0 :(得分:0)
您必须将editData服务注入控制器:
crudApp.controller = ("modalContent",
function($scope,editData) {
$scope.inputs = editData.editArrayy;
});
答案 1 :(得分:0)
我认为问题是由将角度代码包装到updateData()
方法中引起的。
这是您在ng-app指令中引用crudTest模块时出现错误Failed to instantiate module crudTest
的原因。
为什么要将它包装在一个函数中?这个函数在哪里被调用?