Tutorial 12.7 Isolating the Scope of a Directive 2
******************************************INDEX.HTML*****************************************************
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-directive-isolate-production</title>
<script src="//code.angularjs.org/snapshot/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="docsIsolateScopeDirective">
<div ng-controller="Controller">
<my-customer info="naomi"></my-customer>
<hr>
<my-customer info="igor"></my-customer>
</div>
</body>
</html>
******************************************INDEX.HTML*****************************************************
********************************************script.js***************************************************
(function(angular) {
'use strict';
angular.module('docsIsolateScopeDirective', [])
.controller('Controller', ['$scope', function($scope) {
$scope.naomi = { name: 'Naomi', address: '1600 Amphitheatre' };
$scope.igor = { name: 'Igor', address: '123 Somewhere' };
}])
.directive('myCustomer', function() {
return {
restrict: 'E',
scope: {
customerInfo: '=info'
},
templateUrl: 'my-customer-iso.html'
};
});
})(window.angular);
********************************************script.js***************************************************
*******************************************my-customer-iso.html***************************************************
Name: {{customer.name}} Address: {{customer.address}}
*******************************************my-customer-iso.html***************************************************
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-directive-isolate-production</title>
<script src="//code.angularjs.org/snapshot/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="docsIsolateScopeDirective">
<div ng-controller="Controller">
<my-customer info="naomi"></my-customer>
<hr>
<my-customer info="igor"></my-customer>
</div>
</body>
</html>
******************************************INDEX.HTML*****************************************************
********************************************script.js***************************************************
(function(angular) {
'use strict';
angular.module('docsIsolateScopeDirective', [])
.controller('Controller', ['$scope', function($scope) {
$scope.naomi = { name: 'Naomi', address: '1600 Amphitheatre' };
$scope.igor = { name: 'Igor', address: '123 Somewhere' };
}])
.directive('myCustomer', function() {
return {
restrict: 'E',
scope: {
customerInfo: '=info'
},
templateUrl: 'my-customer-iso.html'
};
});
})(window.angular);
********************************************script.js***************************************************
*******************************************my-customer-iso.html***************************************************
Name: {{customer.name}} Address: {{customer.address}}
*******************************************my-customer-iso.html***************************************************
Comments
Post a Comment