关于Angular中directive的简单应用
来源:互联网 发布:淘宝二手钢琴能买吗 编辑:程序博客网 时间:2024/06/08 01:16
用angular中directive方法(自定义插件),实现一个类似与下拉列表的简单的点击显示案例
1.贴出html + js 代码
<body ng-controller="dirController"><hello></hello> <!--自定义控件--><script src="js/angular.min.js"></script><script> var app = angular.module("app",[]); app.directive('hello',function(){ return { restrict:'E', templateUrl:'view/view1.html',//显示内容放在view.html中 replace:false, link : function(scope, element, attrs) { scope.conShow = false; scope.showDiv = function toggle() { scope.conShow = !scope.conShow; } scope.pdd = [ {id:1,'name':'AAA'}, {id:2,'name':'BBB'}, {id:3,'name':'CCC'} ]; scope.clicked = function(index){ scope.conClick = scope.pdd[index].name; scope.conShow = !scope.conShow; } } }; }); app.controller('dirController',function($scope){ });</script></body>
2. 附上view1.html代码
<div> <input type="text" class="label" ng-model="conClick"> <div class="divTop" ng-click="showDiv()">Click Here!</div> <div class="conDiv" ng-show="conShow"> <div ng-repeat="p in pdd"> <a class="link" ng-click="clicked($index)">{{p.name}}</a> </div> </div></div>
3. 运行试试
看见显示选择框,点击显示选中内容
0 0
- 关于Angular中directive的简单应用
- angular中directive的scope用法
- Angular中app-directive的基本构成
- angular directive中scope:{}
- angular directive的使用
- 简单的angular应用
- angular指令的简单案例和解释directive
- angular的directive中自定义属性作为条件中转
- angular 简单的服务应用
- angular路由的简单应用
- angular directive
- angular directive
- angular中,controller、directive和factory
- angular的directive的属性和用法
- angular的directive指令的link方法
- angularjs的controller directive angular-resource
- angular的初步学习——简单的angular应用
- angular 2.0 关于新版angular-cli的应用
- 【JZOJ3296】【SDOI2013】刺客信条(assassin)
- 一次偶然的ajax请求导致status为canceled的原因
- 示波法测血压原理
- js对象
- [Android L]SEAndroid开放设备文件结点权限(读或写)方法(涵盖常用操作:sys/xxx、proc/xxx、SystemProperties)热门干货
- 关于Angular中directive的简单应用
- 数据库查询
- jsp
- 二维数组的动态创建和释放
- iOS 崩溃Crash解析
- 完全背包问题-含优化
- oracle事务
- opencv膨胀与腐蚀
- LeetCode OJ 56. Merge Intervals