Last active
December 26, 2015 17:09
-
-
Save allenyang79/7184685 to your computer and use it in GitHub Desktop.
angular scope isolated Attribute 比較
=,直接綁定到另一個外部變數上
@,用來邦angular 的expression,可以用scope.$eval(attr.var) 來解析
&,用來綁方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app=angular.module "app",[] | |
app.controller "Ctrl",($scope)-> | |
console.log "Ctrl start" | |
$scope.ctrlHeroName="CTRL HERO NAME" | |
app.directive "hero",()-> | |
return { | |
scope: | |
heroName:"=" | |
skill:"@" | |
restrict:"EA" | |
template:""" | |
<div>you are my {{heroName}}</div> | |
""" | |
link:(scope,elements,attrs)-> | |
console.log "hero start" | |
console.log scope.heroName | |
console.dir attrs.skill | |
console.log "before parse" | |
console.dir scope.skill | |
scope.skill=scope.$eval(attrs.skill); | |
console.log "agter parse" | |
console.dir scope.skill | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> | |
</head> | |
<body> | |
<div ng-app="app" ng-controller="Ctrl"> | |
<hero hero-name="ctrlHeroName" skill="{aa:'AA',bb:'BB'}"></hero> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment