Skip to content

Instantly share code, notes, and snippets.

@allenyang79
Last active December 26, 2015 17:08
Show Gist options
  • Save allenyang79/7184622 to your computer and use it in GitHub Desktop.
Save allenyang79/7184622 to your computer and use it in GitHub Desktop.
test angular to parse @ attribute $eval and @parse
app=angular.module "app",[]
app.controller "Ctrl",($scope)->
console.log "Ctrl start"
$scope.heroName="susus"
app.directive "hero",()->
return {
restrict:"EA"
template:"""
<div>you are my {{heroName}}</div>
"""
link:(scope,elements,attrs)->
console.log "hero"
console.dir attrs.skill
scope.skill=scope.$eval(attrs.skill);
console.log "parse"
console.dir scope.skill
}
<!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 hreo-name="balabala" 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