directive例子2

(function() {
angular.module('app.widgets')
.directive('bsModalPlus', function($window, $sce, $modal) {
return {
restrict: 'A',
scope: true,
link: function(scope, element, attr, transclusion) {
// Directive options
var options = { scope: scope, element: element, show: false };
angular.forEach(['template', 'templateUrl', 'controller', 'controllerAs', 'contentTemplate', 'placement', 'backdrop', 'keyboard', 'html', 'container', 'animation', 'backdropAnimation', 'id', 'prefixEvent', 'prefixClass'], function(key) {
if (angular.isDefined(attr[key])) options[key] = attr[key];
});
// Default template url
if (!options['templateUrl'] || options['templateUrl'].length == 0)
options['templateUrl'] = 'widgets/modal/modal.template.html'
// use string regex match boolean attr falsy values, leave truthy values be
var falseValueRegExp = /^(false|0|)$/i;
angular.forEach(['backdrop', 'keyboard', 'html', 'container'], function(key) {
if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key]))
options[key] = false;
});
// Support scope as data-attrs
angular.forEach(['title', 'content'], function(key) {
attr[key] && attr.$observe(key, function(newValue, oldValue) {
scope[key] = $sce.trustAsHtml(newValue);
});
});
//default container and placement
if (!options['container'])
options['container'] = 'body';
if (!options['backdrop'])
options['backdrop'] = 'static';
if (!options['placement'])
options['placement'] = 'center';
options['animation'] = 'am-fade-and-slide-top'
// Support scope as an object
scope.$data = {};
attr.bsModalPlus && scope.$watch(attr.bsModalPlus, function(newValue, oldValue) {
if (angular.isObject(newValue)) {
angular.extend(scope.$data, newValue);
} else {
scope.content = newValue;
}
}, true);
scope.showOkButton = !attr.showOkButton || attr.showOkButton == "true";
scope.showCloseButton = !attr.showCloseButton || attr.showCloseButton == "true";
// Initialize modal
var modal = $modal(options);
scope.$ok = function() {
if (scope.$broadcast("ok").defaultPrevented)
modal.hide();
};
scope.$close = function() {
scope.$broadcast("close");
modal.hide();
};
// Trigger
element.on(attr.trigger || 'click', modal.toggle);
// Garbage collection
scope.$on('$destroy', function() {
if (modal) modal.destroy();
options = null;
modal = null;
});
}
};
});
})();
directive例子2的更多相关文章
- directive例子1
(function() { 'use strict'; angular.module('app.widgets') .directive('confirm', ['confirm2', 'toastr ...
- vuejs心法和技法
原文地址:http://www.cnblogs.com/kidsitcn/p/5409994.html 所有的vuejs组件都是被扩展的vue实例: var MyComponent = Vue.ext ...
- AngularJS directive入门例子
这是<AngularJS>这本书里面提供的一个例子: JS代码: var expanderModule=angular.module('expanderModule', []) expan ...
- Directive间的通信
Directive间的通信 源自大漠的<AngularJS>5个实例详解Directive(指令)机制 这个例子主要的难点在于如何在子Expander里面访问外层Accordion的sco ...
- AngularJS之Directive(三)
前言 angular核心部分如下图几大块,最重要的莫过于指令这一部分,本文将重点讲解指令这一部分,后续笔者将通过陆续的学习来叙述其他如:factory.service等,若有叙述错误之处,欢迎各位指正 ...
- Angular自定义指令directive:scope属性
在AngularJS中,除了内置指令如ng-click等,我们还可以自定义指令.自定义指令,是为了扩展DOM元素的功能.代码中,通过指定directive中的restrict属性,来决定这个指令是作为 ...
- angular.js 例子
angular.js是一个前端的MVC框架,12年的时候曾近在一个portal平台的项目中使用过. 下面给出一个angular.js的典型例子,涵盖一些基础的知识点,用以复习备忘: <html ...
- AngularJS中Directive指令系列 - scope属性的使用
文章是转的,我做下补充.原文地址:https://segmentfault.com/a/1190000002773689 每当一个指令被创建的时候,都会有这样一个选择,是继承自己的父作用域(一般是外部 ...
- [译]Exploring Angular 1.3: Binding to Directive Controllers
原文: http://blog.thoughtram.io/angularjs/2015/01/02/exploring-angular-1.3-bindToController.html Angul ...
随机推荐
- ssl tls 证书链 根证书和叶证书查询
你基本上需要做的是构建一个证书链,如果你没有得到它作为一个链.证书链基本上由第零个位置的最终实体证书(也是叶证书,链中最重要的证书)组成,其次是次要证书. CA证书是最不重要的. 所以这是通常的X.5 ...
- svn分支使用 SVN trunk(主线) branch(分支) tag(标记) 用法详解和详细操作步骤
比较好的介绍了分支的创建和使用. 转:http://blog.csdn.net/vbirdbest/article/details/51122637
- 顺序容器----顺序容器操作,vector对象如何增长,额外的string操作,容器适配器
一.顺序容器操作 1.向顺序容器添加元素 向顺序容器(array除外)添加元素的操作: 操作 说明 c.push_back(t) 在c的尾部创建一个值为t的元素.返回void c.emplace_ba ...
- vue2.x 父组件监听子组件事件并传回信息
利用vm.$emit 1.在父组件中引用子组件 <child @from-child-msg="listenChildMsg"></child > 2.子组 ...
- php 图片添加水印和二维码
$host = $_SERVER['HTTP_HOST']; $save_code_file = './qrcodes/qrcode.png'; QrCode::format()->backgr ...
- 【资料收集】QT 环境安装配置
(很详细,极力推荐) [OpenCV] -- win7下配置OpenCV的Qt开发环境 - 代码人生 - 博客频道 - CSDN.NET http://blog.csdn.net/qiurisuix ...
- SpringBoot document notes
图片拷贝不过来,直接从github上下载 . 链接: https://github.com/DFX339/SpringBootDocumentNotes.git Create a example po ...
- Java使用POI插件将数据以excel形式备份
将数据以表格形式进行备份 (1)导入poi的jar包 放入lib下: WebRoot\WEB-INF\lib\poi-3.2-FINAL-20081019.jar 下载链接:https://gith ...
- selenium(七)expected_conditions EC
判断一个元素是否存在,如何判断alert弹窗出来了,如何判断动态的元素等等一系列的判断,在selenium的expected_conditions模块收集了一系列的场景判断方法, 一.功能介绍和翻译 ...
- java 实现简单链式队列
package com.my; /** * 链式队列 * @author wanjn * */ public class LinkedQueue { private Node head; privat ...