<!-- lang: js -->
myapp = angular.module("myapp", []);
myapp.directive('div', function() {
var directive = {};
directive.restrict = 'E'; /* restrict this directive to elements */
directive.template = "My first directive: {{textToInsert}}";
return directive;
});
<!-- lang: js --> <div ng-controller="MyController" > <div>This div will be replaced</div> </div>
<!-- lang: js -->
My first directive: {{textToInsert}}
<!-- lang: js -->
myapp = angular.module("myapp", []);
myapp.directive('div', function() {
var directive = {};
directive.restrict = 'E'; /* restrict this directive to elements */
directive.template = "My first directive: {{textToInsert}}";
return directive;
});
<!-- lang: js -->
myapp = angular.module("myapp", []);
myapp.directive('div', function() {
var directive = {};
directive.restrict = 'E'; /* restrict this directive to elements */
directive.templateUrl = "/myapp/html-templates/div-template.html";
return directive;
});
<!-- lang: js -->
myapp = angular.module("myapp", []);
myapp.directive('userinfo', function() {
var directive = {};
directive.restrict = 'E'; /* restrict this directive to elements */
directive.templateUrl = "/myapp/html-templates/userinfo-template.html";
return directive;
});
<!-- lang: js --> <userinfo></userinfo> <userinfo></userinfo>
<!-- lang: js -->
myapp.directive('userinfo', function() {
var directive = {};
directive.restrict = 'E';
directive.template = "User : {{user.firstName}} {{user.lastName}}";
directive.scope = {
user : "=user"
}
return directive;
})
<!-- lang: js --> <userinfo user="jakob"></userinfo> <userinfo user="john"></userinfo>
<!-- lang: js -->
<userinfo user="jakob"></userinfo>
<userinfo user="john"></userinfo>
<script>
myapp.directive('userinfo', function() {
var directive = {};
directive.restrict = 'E';
directive.template = "User : <b>{{user.firstName}}</b> <b>{{user.lastName}}</b>";
directive.scope = {
user : "=user"
}
return directive;
});
myapp.controller("MyController", function($scope, $http) {
$scope.jakob = {};
$scope.jakob.firstName = "Jakob";
$scope.jakob.lastName = "Jenkov";
$scope.john = {};
$scope.john.firstName = "John";
$scope.john.lastName = "Doe";
});
</script>
<!-- lang: js -->
<script>
myapp = angular.module("myapp", []);
myapp.directive('userinfo', function() {
var directive = {};
directive.restrict = 'E'; /* restrict this directive to elements */
directive.compile = function(element, attributes) {
// do one-time configuration of element.
var linkFunction = function($scope, element, atttributes) {
// bind element to data in $scope
}
return linkFunction;
}
return directive;
});
</script>
<!-- lang: js -->
<div ng-controller="MyController" >
<userinfo >This will be replaced</userinfo>
</div>
<script>
myapp = angular.module("myapp", []);
myapp.directive('userinfo', function() {
var directive = {};
directive.restrict = 'E'; /* restrict this directive to elements */
directive.compile = function(element, attributes) {
element.css("border", "1px solid #cccccc");
var linkFunction = function($scope, element, attributes) {
element.html("This is the new content: " + $scope.firstName);
element.css("background-color", "#ffff00");
}
return linkFunction;
}
return directive;
})
myapp.controller("MyController", function($scope, $http) {
$scope.cssClass = "notificationDiv";
$scope.firstName = "Jakob";
$scope.doClick = function() {
console.log("doClick() called");
}
});
</script>
<!-- lang: js -->
<div ng-controller="MyController" >
<userinfo >This will be replaced</userinfo>
</div>
<script>
myapp = angular.module("myapp", []);
myapp.directive('userinfo', function() {
var directive = {};
directive.restrict = 'E'; /* restrict this directive to elements */
directive.link = function($scope, element, attributes) {
element.html("This is the new content: " + $scope.firstName);
element.css("background-color", "#ffff00");
}
return directive;
})
myapp.controller("MyController", function($scope, $http) {
$scope.cssClass = "notificationDiv";
$scope.firstName = "Jakob";
$scope.doClick = function() {
console.log("doClick() called");
}
});
</script>
<!-- lang: js -->
<mytransclude>This is a transcluded directive {{firstName}}</mytransclude>
<!-- lang: js -->
<mytransclude>This is a transcluded directive {{firstName}}</mytransclude>
<script>
myapp = angular.module("myapp", []);
myapp.directive('mytransclude', function() {
var directive = {};
directive.restrict = 'E'; /* restrict this directive to elements */
directive.transclude = true;
directive.template = "<div class='myTransclude' ng-transclude></div>";
return directive;
});
myapp.controller("MyController", function($scope, $http) {
$scope.firstName = "Jakob";
});
</script>
<!-- lang: js -->
This is a transcluded directive {{firstName}}
<!-- lang: js --> "<div class='myTransclude' ng-transclude></div>"
<!-- lang: js -->
<mytransclude>
<div class='myTransclude' ng-transclude>
<span class="ng-scope ng-binding">This is a transcluded directive Jakob</span>
</div>
</mytransclude>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有