加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS将数据传递给引导模态

发布时间:2020-12-17 08:23:10 所属栏目:安全 来源:网络整理
导读:我觉得我错过了一些东西,但不能弄清楚什么。 基本上我正在尝试传递一个对象到模态如下,但不是得到传递的对象我得到null …所以我认为是范围的问题,但我是新的角度,需要一些帮助。 控制器 app.controller("musicViewModel",function ($scope,$http,$locat
我觉得我错过了一些东西,但不能弄清楚什么。
基本上我正在尝试传递一个对象到模态如下,但不是得到传递的对象我得到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>
我建议您通过自己的控制器的范围,而不是再次传递相同的控制器,通过这样做,您也可以删除解决方案。
var modalInstance = $uibModal.open({
    templateUrl: 'myModalContent.html',scope: $scope,//passed current scope to the modal
    size: 'lg'
});

否则,您需要创建一个新的控制器,并分配该控制器的模式,同时打开它。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读