2015-10-17 76 views
2

我是新角js 我必须打开一个模式对话框,显示一些选定的值。角模态 - 从一开始就显示模态,我不能隐藏它

打开模态

<div modal="showModal" close="cancel()"> 
     <div class="modal-header"> 
      <h4>Modal Dialog</h4> 
     </div> 
     <div class="modal-body"> 
      <p>E{{inputValue}}</p> 
     </div> 
     <div class="modal-footer"> 
      <button class="btn btn-success" ng-click="ok()">Okay</button> 
      <button class="btn" ng-click="cancel()">Cancel</button> 
     </div> 
    </div> 

对于包含模态的模块的控制器是:

var app = angular.module('myApp', ['ui.bootstrap.modal']); 
    app.controller('ctrlTags', function($scope){ 
     $scope.inputValue=$('input:checked').val() 
     $scope.open = function() { 
      $scope.showModal = true; 
      return $scope.inputValue; 
     }; 

     $scope.ok = function() { 
      $scope.showModal = false; 
     }; 

     $scope.cancel = function() { 
      $scope.showModal = false; 
     }; 
    }); 

出于某种原因,如它是在网页的常规部分被显示的模态(没有按不起作用模式)

+0

首先,您应该更正依赖模块的名称。使用'ui.bootstrap'而不是'ui.bootstrap.modal'。 –

+0

@Hamlet Hakobyan-它没有帮助 –

回答

1

切换布尔值不是如何打开ui-boostrap模式。请参阅documentation。基本上,你必须调用$uibModal.open与模板:

$scope.open = function() { 
    var modalInstance = $uibModal.open({ 
     templateUrl: 'myModal.html', 
     controller: 'ModalInstanceCtrl' 
    }); 
} 

看一看at this plunker在那里我传递一个值的模式,通过$uibModal.openresolve财产。

+0

Michael P. Bazos-如果我需要返回一些值? –

+0

从模态控制器中,将一些数据传递给'close'函数。然后用'$ modalInstance.result.then(...)'得到这个数据。 –

+0

Michael P. Bazos-我应该在then()中写什么......对不起,我是angular.js中的新成员 –