Javascript TypeError:无法读取属性';打开';未定义模态的定义
我试图用某个项目的信息显示一个模态。但当我调用函数时,它会显示: TypeError:无法读取作用域处未定义的属性“open”。$Scope.OpenModel 我希望有人能告诉我原因,以下是相关代码: 模板Javascript TypeError:无法读取属性';打开';未定义模态的定义,javascript,html,angularjs,angularjs-directive,Javascript,Html,Angularjs,Angularjs Directive,我试图用某个项目的信息显示一个模态。但当我调用函数时,它会显示: TypeError:无法读取作用域处未定义的属性“open”。$Scope.OpenModel 我希望有人能告诉我原因,以下是相关代码: 模板 <div ng-controller="View1Ctrl"> <script type="text/ng-template" id="myModalContent.html"> <div class="modal-header">
<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>
控制器
'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正在加载,但没有正确显示
您的注射签名不正确。您缺少
$uiModal
。注意以下几点
.controller('View1Ctrl', ['$scope', 'itemsService',
function($scope, itemsService, $uiModal) {
<script type="text/ng-template" id="templates/modalTemplate.html">
<!-- <div> -->
=>
我不完全确定您打算注入的服务的确切名称。我猜这里基于名为$uiModal
的变量,但是我注意到它的状态是$uibModal
。您需要对此进行验证
作为对最新发现问题的回应,我最好的观察是
templateUrl:“
和
必须匹配。尝试将您的
标记更改为以下内容
.controller('View1Ctrl', ['$scope', 'itemsService',
function($scope, itemsService, $uiModal) {
<script type="text/ng-template" id="templates/modalTemplate.html">
<!-- <div> -->
我在玩文档中找到的文件时偶然发现了这一点。如果两个值不相同,则会出现错误。您是对的,但名称必须更改为uibModal,显然是他们更改了它。缺点是,当我点击按钮时,模式不会显示(没有错误),他只是在我在文档中查找后编辑了我的问题;)不确定为什么它可能没有显示,至少你的错误已经消失了。我可以看得更远一点……奇怪的是,我不确定你提供了什么。你能提供一个复制问题的plunker吗?我尽了最大努力猜测问题是什么,但我有点不知所措,因为第一个问题是修复。至少看看我编辑的建议?希望能有帮助