我正在尝试打开弹出屏幕我收到此错误:
**
Error: Unknown provider: $modalProvider <- $modal
at Error (native)
at file:///C:/Users/asd/Desktop/angular/angularproject/angular.js:2682:42
at Object.getService [as get] (file:///C:/Users/asd/Desktop/angular/angularproject/angular.js:2810:39)
at file:///C:/Users/asd/Desktop/angular/angularproject/angular.js:2687:45
at getService (file:///C:/Users/asd/Desktop/angular/angularproject/angular.js:2810:39)
at invoke (file:///C:/Users/asd/Desktop/angular/angularproject/angular.js:2828:13)
at Object.instantiate (file:///C:/Users/asd/Desktop/angular/angularproject/angular.js:2860:23)
at $get (file:///C:/Users/asd/Desktop/angular/angularproject/angular.js:4743:24)
at file:///C:/Users/asd/Desktop/angular/angularproject/angular.js:4322:17
at forEach (file:///C:/Users/asd/Desktop/angular/angularproject/angular.js:140:20)
为什么我收到此错误..我的Html和js文件是什么?
<!doctype html>
<html ng-app="plunker">
<head>
<script src="angular.js"></script>
<script src="ui-bootstrap-tpls-0.2.0.js"></script>
<link href="bootstrap-combined.min.css" rel="stylesheet">
<script src="index.js"></script>
</head>
<body>
<div ng-controller="DialogDemoCtrl">
<div header-info innerHtm="inner_text"></div>
<a class="btn" data-toggle="modal" href="" ng-click="openPopupScreen()">Add Contend</a>
</div>
</body>
</html>
**
这是我的js文件:
var myApp = angular.module('plunker', ['ui.bootstrap']);
myApp.directive('headerInfo', function(){
alert('dd')
return {
restrict: 'A',
scope: {
inner_htm: '=innerHtm'
},
templateUrl:'dialog.html',
link: function(scope, element, attrs) {
console.log(scope.inner_html);
console.log(element);
console.log(element.html());
scope.inner_htm = element.html();
console.log(scope.inner_htm);
}
}
})
myApp.controller('DialogDemoCtrl', function($scope, $modal, $log) {
$scope.items = [];
$scope.activeItem = {
id:'',
name: '',
content: ''
};
$scope.addItem = function () {
$scope.activeItem.id = $scope.items.length + 1;
$scope.items.push($scope.activeItem);
$scope.activeItem = {}; /* reset active item*/
};
$scope.getId = function (item) {
alert('ID: '+item.id);
};
$scope.openPopupScreen = function () {
alert('---')
var modalInstance = $modal.open({
template: $scope.inner_text,
controller: ModalInstanceCtrl
});
};
});
这里是我们的Dialog.html
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h1>Add Element</h1>
</div>
<div class="modal-body">
<form >
<label>Name:</label><input type="text" class="span3" ng-model="activeItem.name"></br>
<label>Content Name:</label><input type="password" class="span3" ng-model="activeItem.content"></br>
<button type="submit" class="btn btn-success" ng-click="addItem()">Add In List</button>
<button type="reset" class="btn ">Clear</button>
</form>
</div>
<div class="modal-footer">
<a class="btn" data-dismiss="modal" aria-hidden="true">close</a>
</div>
我不知道为什么会收到这个错误..我对这个错误太沮丧了?
答案 0 :(得分:1)
得到问题$ modal在0.6.0中添加
<script src="ui-bootstrap-tpls-0.2.0.js"></script>
请使用最新版本
答案 1 :(得分:0)
请参阅此处:http://plnkr.co/edit/0u9YyKkkaRIwnuazqFwC?p=preview并将以下代码添加到您的app.js
var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.ok = function() {
$modalInstance.close($scope.selected.item);
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
};