码迷,mamicode.com
首页 > Web开发 > 详细

AngularJs + Bootstrap

时间:2016-04-23 16:48:10      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:

 

技术分享

JS:

var mymodal = angular.module(mymodal, []);

mymodal.controller(MainCtrl, function ($scope) {
    $scope.showModal = false;
    $scope.toggleModal = function(){
        $scope.showModal = !$scope.showModal;
    };
  });

mymodal.directive(modal, function () {
    return {
      template: <div class="modal fade"> + 
          <div class="modal-dialog"> + 
            <div class="modal-content"> + 
              <div class="modal-header"> + 
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> + 
                <h4 class="modal-title">{{ title }}</h4> + 
              </div> + 
              <div class="modal-body" ng-transclude></div> + 
            </div> + 
          </div> + 
        </div>,
      restrict: E,
      transclude: true,
      replace:true,
      scope:true,
      link: function postLink(scope, element, attrs) {
        scope.title = attrs.title;

        scope.$watch(attrs.visible, function(value){
          if(value == true)
            $(element).modal(show);
          else
            $(element).modal(hide);
        });

        $(element).on(shown.bs.modal, function(){
          scope.$apply(function(){
            scope.$parent[attrs.visible] = true;
          });
        });

        $(element).on(hidden.bs.modal, function(){
          scope.$apply(function(){
            scope.$parent[attrs.visible] = false;
          });
        });
      }
    };
  });

 

AngularJs + Bootstrap

标签:

原文地址:http://www.cnblogs.com/91allan/p/5424845.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!