Created
December 11, 2014 01:45
-
-
Save niisar/3f1efad89ee77ba05464 to your computer and use it in GitHub Desktop.
Isolating Scope in Directive.
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 xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title></title> | |
<script src="js/angular.js"></script> | |
<script> | |
myapp = angular.module("myapp", []); | |
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.nisar = {}; | |
$scope.nisar.firstName = "Nisar"; | |
$scope.nisar.lastName = "Mohammed"; | |
$scope.rabi = {}; | |
$scope.rabi.firstName = "Rabi"; | |
$scope.rabi.lastName = "Sharma"; | |
}); | |
</script> | |
</head> | |
<body ng-app="myapp" ng-controller="MyController"> | |
<userinfo user="nisar"></userinfo> | |
<userinfo user="rabi"></userinfo> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment