微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angularjs – 通过id值到离子模态点击

我正在使用点击事件来打开这样的模态窗口,

但是在这个点击事件上,我需要传递一个id值,以便我可以把这个id的值显示出来,这是控制器的一部分,

$ionicModal.fromTemplateUrl('modal.html',function($ionicModal) {
                $scope.modal = $ionicModal;
            },{
                // Use our scope for the scope of the modal to keep it simple
                scope: $scope,// The animation we want to use for the modal entrance
                animation: 'slide-in-up'
            });

有什么办法吗?

谢谢.

您将当前范围分配给您的模态,因此您可以将变量分配给$scope对象:
$ionicModal.fromTemplateUrl('modal.html',function($ionicModal) {
    $scope.modal = $ionicModal;
},{
    // Use our scope for the scope of the modal to keep it simple
    scope: $scope,// The animation we want to use for the modal entrance
    animation: 'slide-in-up'
});

$scope.openModal = function(id) {
    $scope.selectedId = id;
    $scope.modal.show();
}

在你看来:

<ul>
    <li ng-repeat="item in items"
        ng-click="openModal(item.id)">
        {{ item.name }}
    </li>
</ul>

那么你可以访问你的模式中的id:

<div class="modal">
    <h1>{{ selectedId }}</h1>
</div>

原文地址:https://www.jb51.cc/angularjs/140524.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐