angluarjs中指令的使用方式
2015-08-18 22:50
591 查看
本人初学者,如有不足虚心求教!
angular指令的模块可以分下面几个部分:
restrict:用于操作dom的[E]元素,[A]属性,[C]样式,同时也能组合使用
priority:设置当前指令的优先级,用于同一个页面下面调用不同指令的时候
replace:用于替换dom元素
template:定义指令模版
templateUrl:用url的加载方式加载模版
controller:在指令中添加控制器,可以用自己$scope的作用域
link:用于绑定dom元素事件的,可以设置数据绑定
下面一个简单的例子:
angular指令的模块可以分下面几个部分:
restrict:用于操作dom的[E]元素,[A]属性,[C]样式,同时也能组合使用
priority:设置当前指令的优先级,用于同一个页面下面调用不同指令的时候
replace:用于替换dom元素
template:定义指令模版
templateUrl:用url的加载方式加载模版
controller:在指令中添加控制器,可以用自己$scope的作用域
link:用于绑定dom元素事件的,可以设置数据绑定
下面一个简单的例子:
angular.module('expanderModule', []) .directive('expander', function(){ return { restrict: 'EA', replace: true, transclude: true, scope: { title:'=expanderTitle' }, template: '<div>' + '<div class="title" ng-click="toggle()">{{title}}</div>' + '<div class="body" ng-show="showMe" ng-transclude></div>' + '</div>', link: function(scope, element, attrs) { scope.showMe = false; scope.toggle = function toggle() { scope.showMe = !scope.showMe; } } } });
相关文章推荐
- lua中实现的base64加密
- 【Lua 第一篇】 Manager + Data 的定义与应用
- Lua语言介绍
- ulua
- ****************本文是Lua编写的游戏接入多盟SDK*******************
- leetcode 150 —— Evaluate Reverse Polish Notation
- lua——元表、元方法、继承
- A*寻路算法lua实现
- Lua语言基础
- ngx_lua 模块API说明
- window下编译lua源码,编译lua的库文件,编译lua解释器,编译lua编译器
- Lua中的面向对象
- uLua拆分MonoBehavior逻辑
- lua_next函数分析
- Mac下 Lua 添加库 luafilesystem
- 用Lua扩展谷歌拼音输入法
- 【Lua】tolua
- Lua.LearningLua.7-userdata
- 【Lua】__newindex
- Lua学习笔记--环境配置&Hello World