Here is an example of using the $attrs method in angularJS:
无标题文档
a_directive
原始内容
原始内容
原始内容
<script><br /> var app = angular.module('Demo', [], angular.noop);<br /> app.controller("TestCtrl",<br /> function($scope) {<br /> $scope.name = "qihao";<br /> });<br /> app.directive("t",<br /> function() {<br /> return {<br /> controller : function($scope){$scope.name = "qq"},<br /> template : "<div>test:implementToParent{{name}}</script>
replace : true,
scope : true //作用域是继承的,默认就是继承的
}
});
app.directive("t2",
function() {
return {
controller : function($scope){$scope.name = "nono"},
template : "
replace : true,
restrict : "AE"
}
});
app.directive("t3",
function() {
return {
template : "
title2Is:{{title2}}
replace : true,
restrict : "AE",
scope : {
title : "@t3",
title2 : "@title2"
}
}
});
app.directive('a',
function() {
var func = function() {
console.log('compile');
return function() {
console.log('link');
}
}
var controller = function($scope, $element, $attrs, $transclude) {
//$transclude :是指令标签的复制体
console.log('controller');
console.log($scope);
console.log($transclude);
//$transclude接受两个参数,你可以对这个克隆的元素进行操作,
var node = $transclude(function(clone_element, scope) {
$element.append(clone_element);
$element.append("spanTag___");
console.log(clone_element);
console.log('--');
console.log(scope);
});
console.log(node);
}
return {
compile: func,
template: "",
controller: controller,
transclude: true,
restrict: 'AE'
}
});
app.directive('compile',function() {
var func = function() {
console.log('a compile');
return {
pre: function() {
console.log('a link pre')
},
post: function() {
console.log('a link post')
},
}
}
return {
restrict : "AE",
compile : func
}
})
app.directive('test', function(){
var func = function($element, $attrs){
console.log($attrs);
$attrs.$observe('a', function(new_v){
console.log(new_v);
});
}
return {compile: func,
restrict: 'E'}
});
app.controller('TestCtrl', function($scope){
$scope.a = 123;
});
app.directive('te', function(){
var func = function($scope,$element, $attrs,$ctrl){
console.log($ctrl)
//$attrs.$set. 给这个属性设置b,值为ooo,就是这样
$attrs.$set('b', 'ooo');
$attrs.$set('a-b', '11');
//This is a bit unclear //The second parameter value
$attrs.$set('c-d', '11', true, 'c_d');
console.log($attrs);
}
return {
compile: function(){
Return func
},
restrict: 'E'
}
});
app.controller('TestCtrl', function($scope){
$scope.show = function(v){console.log(v);}
});
That’s it for this article. I hope you can have a new understanding of the use of $attrs in angularJS. I hope you like this article.

Javascript 是一个非常有个性的语言. 无论是从代码的组织, 还是代码的编程范式, 还是面向对象理论都独具一格. 而很早就在争论的Javascript 是不是面向对象语言这个问题, 显然已有答案. 但是, 即使 Javascript 叱咤风云二十年, 如果想要看懂 jQuery, Angularjs, 甚至是 React 等流行框架, 观看《黑马云课堂JavaScript 高级框架设计视频教程》就对了。

Vue是一款流行的JavaScript框架,用于构建现代的Web应用程序。Vue提供了一个强大的组件系统,允许您将UI元素分解为可重用的部件,并以可维护的方式组合它们。Vue的组件系统也提供了一种方便的方式来在组件之间传递数据和属性。其中一个非常有用的属性传递方式是$attrs。$attrs是Vue提供的一个特殊对象,用于将组件的HTML属性传递到其子组

在如今信息时代,网站已经成为人们获取信息和交流的重要工具。一个响应式的网站能够适应各种设备,为用户提供优质的体验,成为了现代网站开发的热点。本篇文章将介绍如何使用PHP和AngularJS搭建一个响应式网站,从而提供优质的用户体验。PHP介绍PHP是一种开源的服务器端编程语言,非常适用于Web开发。PHP具有很多优点,如易于学习、跨平台、丰富的工具库、开发效

随着互联网的不断发展,Web应用已成为企业信息化建设的重要组成部分,也是现代化工作的必要手段。为了使Web应用能够便于开发、维护和扩展,开发人员需要选择适合自己开发需求的技术框架和编程语言。PHP和AngularJS是两种非常流行的Web开发技术,它们分别是服务器端和客户端的解决方案,通过结合使用可以大大提高Web应用的开发效率和使用体验。PHP的优势PHP

随着互联网的普及,越来越多的人在使用网络进行文件传输和共享。然而,由于各种原因,使用传统的FTP等方式进行文件管理无法满足现代用户的需求。因此,建立一个易用、高效、安全的在线文件管理平台已成为了一种趋势。本文介绍的在线文件管理平台,基于PHP和AngularJS,能够方便地进行文件上传、下载、编辑、删除等操作,并且提供了一系列强大的功能,例如文件共享、搜索、

随着Web应用程序的普及,前端框架AngularJS变得越来越受欢迎。AngularJS是一个由Google开发的JavaScript框架,它可以帮助你构建具有动态Web应用程序功能的Web应用程序。另一方面,对于后端编程,PHP是非常受欢迎的编程语言。如果您正在使用PHP进行服务器端编程,那么结合AngularJS使用PHP将可以为您的网站带来更多的动态效

随着Web技术的飞速发展,单页Web应用程序(SinglePageApplication,SPA)已经成为一种越来越流行的Web应用程序模型。相比于传统的多页Web应用程序,SPA的最大优势在于用户感受更加流畅,同时服务器端的计算压力也大幅减少。在本文中,我们将介绍如何使用Flask和AngularJS构建一个简单的SPA。Flask是一款轻量级的Py


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
