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>