angular自定义指令
来源:互联网 发布:聚合tv软件 编辑:程序博客网 时间:2024/06/02 13:43
- 简介
- 指令基础
- tabs示例
简介
angular拥有强大的指令功能,其自定义指令能让我们将很多模块组件话。这样我们的代码的复用及有效性将大大提高。 --[文档地址](http://docs.angularjs.cn/api/)
指令基础
- restrict (A)attribute (E)element (C)class (M)comment
- scope 创建指令的作用范围 @传递一个字符串 =绑定父域的一个属性 &使用父域的函数
- replace 是否替换
- tansclude 包含其中内容
angular.module('moduleName').directive(function(){ var directive = { restrict: 'E', //限制作为属性还是元素等 scope: { //设置指令对应的作用域 name: '@', //name值传递 字符串 单向数据绑定 amount: '=', //amount引用传递 双向绑定 save: '&' //保存操作 }, template: //模版 "<div> sdf<div>", replace: ture, //是否替换原始标记 transclude: false,// 不复制原始html内容 controller: moduleController,//控制器 link: function(scope, element, attrs, controller) } //定义controller fucntion moduleController() { } return directive;})
tabs示例
html部分:
<body ng-app='app'> <tabs> <pane title='first tab'> <div>this is first content</div> </pane> <pane title='second tab'> <div>this is second content</div> </pane> </tabs></body>
js部分:
angular.module('app', []) .directive('tabs', function() { return { restrict: 'E', tansclude: true, scope:{}, controller:['$scope', function($scope) { var panes = $scope.panes = []; $scope.select = function(pane) { angular.forEach(panes, function(pane) { pane.selected = false; }) pane.selected = true; } this.addPane = function(pane) { if(panes.length == 0){ $scope.select(pane); } panes.push(pane); } }], template: '<div class='tabable'>' + '<ul class="nav nav-tabs">' + '<li ng-repeat="pane in panes" ng-class="{active:pane.selected}">'+ '<a href="" ng-click="select(pane)">{{pane.title}}</a>' + '</li>' + '</ul>' + '</div>', replace: true } }) .directive('pane', function() { return { restrict: 'E', require: '^tabs'//???, transclude: true, replace: true, scope: { title: '@' } link: function(scope, element, attrs, tabsCtrl) { tabsCtrl.addPanel(scope); } template: '<div class="tabs-pane" ng-click={active: selected} ng-transclude>' + '</div>' } })
0 0
- angular 自定义指令
- angular js自定义指令
- Angular自定义指令(进阶)
- angular自定义指令
- 创建angular自定义指令
- Angular --- 自定义指令更新
- angular 自定义指令
- angular自定义指令templateUrl
- Angular 自定义指令详解
- 一,Angular自定义指令
- Angular自定义指令
- angular自定义指令详解
- angular自定义指令
- angular.js自定义指令
- angular 自定义指令命名
- angular指令和自定义指令
- angular 自定义指令参数详解
- Angular自定义指令(初级)
- RMQ问题的ST算法
- 上传到jcenter的步骤
- LeetCode 34. Search for a Range
- mysql如何查看未使用的索引
- 机器学习与计算机视觉相关资源(不断更新中...)
- angular自定义指令
- WIN10 X64下通过TLS实现反调试
- oc开发笔记3 录音时频率获取 以及声像显示
- 不知道是win10在抽风还是校园网在抽风
- Bzoj3190:[JLOI2013]赛车:半平面交
- PHP中session变量的销毁
- 设计模式(一)简单工厂模式
- U8SDK——支持自动拆分成多个dex文件(MultiDex支持)
- iOS开发:调用相关设备