AngularJS将数据传递到引导模式 [英] AngularJS passing data to bootstrap modal
问题描述
大家好这里我想我失去了一些东西,但找不出什么。
基本上我想要一个对象传递给像下面的模式,而是获得传递的对象我得空......所以我认为是范围的问题,但我在新的角度和需要一些帮助。
控制器
app.controller(musicViewModel功能($范围,$ HTTP,$位置$ uibModal,$日志){$ scope.selected = NULL;$ scope.open =功能(项目){ $ scope.selected =项目; $ log.info('打开'+ $ scope.selected); //获得右路传对象 VAR modalInstance = $ uibModal.open({
templateUrl:myModalContent.html',
控制器:'musicViewModel',
大小:LG,
解析:{
项目:功能(){
返回$ scope.selected;
}
}
});
};$ scope.toggleAnimation =功能(){
$ scope.animationsEnabled = $ scope.animationsEnabled!;
};
});
查看
< DIV CLASS =行NG-控制器=musicViewModel>
<脚本类型=文/ NG-模板ID =myModalContent.html>
< DIV CLASS =模头>
< H3类=模式标题>!我是一个模式< / H3 GT&;
< / DIV>
< DIV CLASS =模体>
< UL>
<立GT;
{{}选择} //总是得到空
< /李>
< / UL>
< / DIV>
< / SCRIPT>
< / DIV>
我建议你通过自己的控制器的范围强似相同<$ C的$ C>控制器
,这样做,你可以删除决心
也。
VAR modalInstance = $ uibModal.open({
templateUrl:myModalContent.html',
适用范围:$范围,通过//当前范围内模态
大小:LG
});
否则,你需要创建一个新的控制器
并分配控制器模式
,同时打开它。
Hi guys here I think I'm missing something but cannot figure what. Basically I'm trying to pass an object to the modal like below, but instead of getting the passed object I gets null...so I think is a problem with the scope but I'm new in Angular and need some help.
Controller
app.controller("musicViewModel", function ($scope, $http, $location, $uibModal, $log) {
$scope.selected = null;
$scope.open = function (item) {
$scope.selected = item;
$log.info('Open' + $scope.selected); // get right passes object
var modalInstance = $uibModal.open({
templateUrl: 'myModalContent.html',
controller: 'musicViewModel',
size: 'lg',
resolve: {
items: function () {
return $scope.selected;
}
}
});
};
$scope.toggleAnimation = function () {
$scope.animationsEnabled = !$scope.animationsEnabled;
};
});
View
<div class="row" ng-controller="musicViewModel">
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body">
<ul>
<li>
{{ selected }} // always gets null
</li>
</ul>
</div>
</script>
</div>
I'd suggest you to pass the scope
of your own controller instead of passing same controller
again, by doing that you can remove the resolve
also.
var modalInstance = $uibModal.open({
templateUrl: 'myModalContent.html',
scope: $scope, //passed current scope to the modal
size: 'lg'
});
Otherwise you need to create a new controller
and assign that controller for modal
while opening it.
这篇关于AngularJS将数据传递到引导模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!