Skip to content

Instantly share code, notes, and snippets.

@niisar
Created December 11, 2014 01:45
Show Gist options
  • Save niisar/3f1efad89ee77ba05464 to your computer and use it in GitHub Desktop.
Save niisar/3f1efad89ee77ba05464 to your computer and use it in GitHub Desktop.
Isolating Scope in Directive.
<!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