为什么undefined不是使用Angular指令来关闭Bootstrap模式的函数

时间:2014-07-02 17:43:03

标签: angularjs twitter-bootstrap

作为Angularjs的新手,我从这里复制了一个指令:Closing Twitter Bootstrap Modal From Angular Controller,以便能够从控制器关闭一个bootstrap模式,在我的实现中,我得到一个未定义的不是函数错误。 (http://jsfiddle.net/jlamont/7f6dH/6/

这里是html

<div ng:app="app">
 <div>
  <ul><li><a href='#' data-toggle="modal" data-target="#loginModal">Login</a></li></ul>

  <div id='loginModal' class='modal fade' myModal ng-controller="LoginDialogController" tabindex="-2" role="dialog" aria-labelledby="loginModal" aria-hidden="true">
   <div class="modal-dialog">
    <div class="modal-content">        
     <div class="modal-header">
       <button type="button" class="close" data-dismiss="modal" ng-click="cancel()">x</button>
       <h3>Login MyApp</h3>
     </div>
     <div class="modal-body">
       <form name="login_form">
        <alert ng-repeat="alert in alerts" type="danger" close="closeAlert($index)">{{alert.msg}}</alert>
      <p><input type="text" class="span3" ng-model="login.user_email"  placeholder="Email" required></p>
      <p><input type="password" class="span3" ng-model='login.password' placeholder="Password" required></p>
      <p><button type="submit" class="btn btn-primary" ng-click="ok()">Sign in</button>
        <a href="#">Forgot Password?</a>
      </p>
       </form>
     </div>
     <div class="modal-footer">
       My.com?
       <a href="#" class="btn btn-primary">Register</a>
     </div>
    </div>
   </div>
  </div>         
 </div>
</div>

这里是js

angular.module("app", []).directive('myModal', function() {
 return {
  restrict: 'A',
  scope:{},
  link: function(scope, element, attr) {
    scope.dismiss = function() {
     element.modal('hide');
    };
  }
   } 
});

function LoginDialogController($scope){
 $scope.ok = function(){
  $scope.dismiss();
 };
}

0 个答案:

没有答案