Angular Bootstrap uibModal无法解析属性 [英] Angular Bootstrap uibModal not resolve attributs
问题描述
角色属性在AngularJS引导uiModel中无法解析.
Roles property not resolve in AngularJS bootstrap uiModel.
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: 100,
resolve: {
roles: function () {
return $scope.roles;
}
}
});
请参阅ngRepeat代码,该代码读取角色的值并制作dom元素.
See ngRepeat code which read the value of Roles and making dom elements.
<ul>
<li ng-repeat="item in roles">
<a href="#" ng-click="$event.preventDefault(); selected.item = item">{{ item.name }}</a>
</li>
</ul>
控制台上也显示错误:错误:[$ injector:unpr]未知提供程序:itemsProvider<-项目<-ModalInstanceCtrl
Also error shows on console : Error: [$injector:unpr] Unknown provider: itemsProvider <- items <- ModalInstanceCtrl
推荐答案
经过某种研究,我发现Angular只解析uiModel中的 items 属性,因此当用户想要从其他属性获取值时然后角度不能正确响应.
After some sort of research I found that Angular only resolve items property in uiModel, so when user want to get values from other attributes then angular not respond properly.
查找更新的代码
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: 100,
resolve: {
items: function () {
return $scope.userInfo;
}
}
});
<ul>
<li ng-repeat="item in items.role">
<a href="#" ng-click="$event.preventDefault(); selected.item = item">{{ item.name }}</a>
</li>
</ul>
说明: $ scope.userInfo 是JSON对象,其中包含角色密钥,而角色包含角色列表
Explaination : $scope.userInfo is the JSON object which contains the role key and role contains the list of role
这篇关于Angular Bootstrap uibModal无法解析属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!