【发布时间】:2016-02-22 03:30:08
【问题描述】:
我正在尝试显示带有特定项目信息的模式。但是当我调用该函数时,它会显示:
TypeError: Cannot read property 'open' of undefined at Scope.$scope.openModal
我希望有人能告诉我原因,这里是相关代码:
模板
<div ng-controller="View1Ctrl">
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title">Item Details</h3>
</div>
<div class="modal-body">
<ul ng-repeat="i in items">
<li>Type: <span ng-bind="i.type"></span></li>
<li>Description: <span ng-bind="i.description"></span></li>
<li>Date: <span ng-bind="i.createDate"></span></li>
<li>Priority: <span ng-bind="i.priority"></span></li>
<li>Finished: <span ng-bind="i.isDone"></span></li>
</ul>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="$close()">OK</button>
</div>
</script>
</div>
App.Js
'use strict';
// Declare app level module which depends on views, and components
angular.module('myApp', [
//'ngRoute',
'ui.router',
'ui.bootstrap',
'myApp.view1',
'myApp.view2',
'myApp.version',
'myApp.items'
])
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/view1');
$stateProvider
.state('view1', {
url: '/view1',
templateUrl: 'view1/view1.html',
controller: 'View1Ctrl'
})
.state('view2', {
url: '/view2',
templateUrl: 'view2/view2.html',
controller: 'View2Ctrl'
});
});
控制器
'use strict';
angular.module('myApp.view1', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/view1', {
templateUrl: 'view1/view1.html',
controller: 'View1Ctrl'
});
}])
.controller('View1Ctrl', ['$scope','itemsService',function($scope,itemsService, $uiModal) {
$scope.$on('itemSwitch.moreInfo', function(event, obj){
$scope.openModal(obj);
});
$scope.openModal = function (obj) {
var modalInstance = $uiModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'templates/modalTemplate.html',
controller: 'View1Ctrl',
resolve: {
items: function () {
return obj;
}
}
});
}
}]); //END
谁能指出我正确的方向来解决这个问题?
谢谢
错误消失了,但现在除了灰屏之外什么都不显示,控制台显示模态 html 正在加载但无法正常显示。
【问题讨论】:
标签: javascript html angularjs angularjs-directive