将控制器传递给$ ionicModal [英] Pass a controller to $ionicModal

查看:114
本文介绍了将控制器传递给$ ionicModal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道你是否可以将控制器传递给$ ionicModal服务。类似的东西。

I am wondering if you can pass a controller to the $ionicModal service. Something like.

$ionicModal.fromTemplateUrl('templates/login.html', {
  scope: $scope,
  controller: 'MyModalCotroller'
})

一点背景:我会喜欢有一个分布在应用程序中的模态,我不想在每个控制器中重复所有方法(隐藏,显示,模态内的按钮),我想从主控制器中删除方法来保存清洁。这将封装模态的功能。

A little context: I would like to have a modal that is distributed across the app and I dont want to repeat all the methods (hide, show, buttons inside the modal) in every controller and I would like to remove the methods from the 'Main Controller' to keep things clean. This would encapsulate the functionality of the modal.

有没有办法做到这一点。
谢谢

Is there a way to do this.? Thanks

推荐答案

只需在模式的html主体中添加要使用的控制器即可。我创建了一个小提示,向您展示离心文档中提供的示例: http://jsfiddle.net/g6pdkfL8 /

Just add the controller you want to use in the body of the html of the modal. I created a fiddle to show you an example based off the one provided in the ionic docs: http://jsfiddle.net/g6pdkfL8/

但基本上是:

<-- template for the modal window -->
<ion-modal-view>
<ion-content ng-controller="ModalController">
 ...
</ion-content>
<ion-modal-view>

这篇关于将控制器传递给$ ionicModal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆