自定义directive,简单实例
来源:互联网 发布:game.min.js是什么 编辑:程序博客网 时间:2024/06/05 08:31
//一个自定义指令的简单例子,自定义directive
<html><head> <title>Angular JS Custom Directives</title></head><body> <h2>AngularJS Sample Application</h2> <div ng-app="mainApp" ng-controller="StudentController"><student name="Mahesh"></student><br/><student name="Piyush"></student> </div> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script> <script> var mainApp = angular.module("mainApp", []); mainApp.directive('student', function() { var directive = {}; directive.restrict = 'E'; directive.template = "Student: <b>{{student.name}}</b> , Roll No: <b>{{student.rollno}}</b>"; directive.scope = { student : "=name" } directive.compile = function(element, attributes) { element.css("border", "1px solid #cccccc"); var linkFunction = function($scope, element, attributes) { element.html("Student: <b>"+$scope.student.name +"</b> , Roll No: <b>"+$scope.student.rollno+"</b><br/>"); element.css("background-color", "#ff00ff"); } return linkFunction; } return directive; }); mainApp.controller('StudentController', function($scope) { $scope.Mahesh = {}; $scope.Mahesh.name = "Mahesh Parashar"; $scope.Mahesh.rollno = 1; $scope.Piyush = {}; $scope.Piyush.name = "Piyush Parashar"; $scope.Piyush.rollno = 2; }); </script></body></html>
0 0
- 自定义directive,简单实例
- 自定义特性简单实例
- 自定义异常简单实例
- 自定义注解简单实例
- anuglarJS directive综合实例
- angularjs directive 实例 详解
- AngularJs directive指令实例
- AngularJs directive-controller实例
- AngularJs directive-link实例
- angularjs之directive实例
- angularjs directive 实例 详解
- angularjs directive 实例 详解
- 自定义 directive ay-box
- AngularJS自定义Directive 详解
- 自定义指令(directive)
- Angular2-自定义指令@Directive
- Vue.directive 自定义指令
- Vue自定义指令(directive)
- Freescale iMX6的u-boot和kermel编译,并生成.dtb
- FireFox开启Notification通知等权限
- CheckStyle检查规则中文翻译
- Boost之字符串
- Java @override报错的解决方法
- 自定义directive,简单实例
- java动态代理(JDK和cglib)
- TCP的TIME_WAIT快速回收与重用
- Android 中与 so 有关的一个大坑
- 116. Populating Next Right Pointers in Each Node
- android内存优化之二加载图片内存优化
- Dreamweaver链接Access数据库IIS配置站点的注意情况
- BZOJ4415 [Shoi2013]发牌
- 自定义cell中使用添加多个图片并自适应cell高度(类型于电商平台的商品评价添加图片)