【问题标题】:Change the template of a modal from within the modal in angular从模态中以角度更改模态的模板
【发布时间】:2017-03-11 20:09:41
【问题描述】:

我打开一个这样的模式:

<a href="#" ng-click="showLogin()">Sign in</a>

登录功能

$scope.showLogin= function() {
    var modalInstance = $uibModal.open({
       templateUrl: 'partials/login.html',
       controller: 'modalController',
   })
 };

ModalController(通用)

angular.module('app.controllers')
    .controller("modalController", function($scope, $uibModalInstance) {

    $scope.cancel = function () {
      $uibModalInstance.dismiss('cancel');
    };

});

登录.html

<form>
</form>
<a href="#" ng-click="showSignup()">Sign up</a>

点击注册后,我可以打开注册模式。这是plunkr:http://plnkr.co/edit/mR3nXYo1rm4ey5Buc9Q0?p=preview

我的问题是,是否可以只交换模板?单击注册时,我想从 register.html 更改模板。

【问题讨论】:

    标签: angularjs angular-ui-bootstrap


    【解决方案1】:

    当然。只需使用

    <div ng-if="model.modalType === 'login'">
      <form>
      </form>
      <a href="#" ng-click="model.modalType = 'signup'">Sign up</a>
    </div>
    <div ng-if="model.modalType === 'signup'">
      ...
    </div>
    

    在你的控制器中:

    $scope.model = {
      modalType: 'login'
    };
    

    【讨论】:

    • 谢谢它的工作。在不污染modalinstanceCtrl的情况下可以做到这一点吗?我想让它保持通用,以便其他模式也可以使用它。
    • 例如,将整个内容嵌套在 &lt;div ng-controller="LoginAndSignupCtrl"&gt; 中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多