基本上我正在尝试传递一个对象到模态如下,但不是得到传递的对象我得到null …所以我认为是范围的问题,但我是新的角度,需要一些帮助。
控制器
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; }; });
视图
<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>