Tutorial 13.1 Creating and Configuring component
******************************************INDEX.HTML*****************************************************
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-heroComponentSimple-production</title>
<script src="//code.angularjs.org/snapshot/angular.min.js"></script>
<script src="index.js"></script>
<script src="heroDetail.js"></script>
</head>
<body ng-app="heroApp">
<!-- components match only elements -->
<div ng-controller="MainCtrl as ctrl">
<b>Hero</b><br>
<hero-detail hero="ctrl.hero"></hero-detail>
</div>
</body>
</html>
********************************************index.js***************************************************
(function(angular) {
'use strict';
angular.module('heroApp', []).controller('MainCtrl', function MainCtrl() {
this.hero = {
name: 'Spawn'
};
});
})(window.angular);
********************************************index.js***************************************************
********************************************heroDetail.js***************************************************
(function(angular) {
'use strict';
angular.module('heroApp').component('heroDetail', {
templateUrl: 'heroDetail.html',
bindings: {
hero: '='
}
});
})(window.angular);
********************************************heroDetail.js***************************************************
********************************************heroDetail.html***************************************************
<span>Name: {{$ctrl.hero.name}}</span>
********************************************heroDetail.html***************************************************
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-heroComponentSimple-production</title>
<script src="//code.angularjs.org/snapshot/angular.min.js"></script>
<script src="index.js"></script>
<script src="heroDetail.js"></script>
</head>
<body ng-app="heroApp">
<!-- components match only elements -->
<div ng-controller="MainCtrl as ctrl">
<b>Hero</b><br>
<hero-detail hero="ctrl.hero"></hero-detail>
</div>
</body>
</html>
********************************************index.js***************************************************
(function(angular) {
'use strict';
angular.module('heroApp', []).controller('MainCtrl', function MainCtrl() {
this.hero = {
name: 'Spawn'
};
});
})(window.angular);
********************************************index.js***************************************************
********************************************heroDetail.js***************************************************
(function(angular) {
'use strict';
angular.module('heroApp').component('heroDetail', {
templateUrl: 'heroDetail.html',
bindings: {
hero: '='
}
});
})(window.angular);
********************************************heroDetail.js***************************************************
********************************************heroDetail.html***************************************************
<span>Name: {{$ctrl.hero.name}}</span>
********************************************heroDetail.html***************************************************
Comments
Post a Comment