最近有点时间,想系统的学习下angular.会把要做笔记的地方记录下,方便以后查询。
Part 1.
对于一个index.html
包括三部分
1. ng-app = "phonecatApp" 定义了作用域
2. ng-controller = "PhoneListController" 定义了controller
3. ng-repeat = "phone in phones" 定义了实现
对于app.js
1.var phonecatApp = angular.module('phonecatApp',[]); 定义phonecatApp module
2. phonecatApp.controller ('PhoneListController', function PhoneListController($scope) {
$scope.phones =[...];
}
tips:
a.ng-repeat = "phone in phones | filter:query" 用来做fitler
index.html -> define <phone-list></phone-list>
In app.module.js
'use strict';
// Define the `phonecatApp` module
angular.module('phonecatApp', [
// ...which depends on the `phoneList` module
'phoneList'
]);
In phone-list.module.js
'use strict';
// Define the `phoneList` module
angular.module('phoneList', []);
In phone-list.component.js
'use strict';
// Register `phoneList` component, along with its associated controller and template
angular.
module('phoneList').
component('phoneList', {
templateUrl: 'phone-list/phone-list.template.html',
controller: function PhoneListController() {
this.phones = [
{
name: 'Nexus S',
snippet: 'Fast just got faster with Nexus S.'
}, {
name: 'Motorola XOOM™ with Wi-Fi',
snippet: 'The Next, Next Generation tablet.'
}, {
name: 'MOTOROLA XOOM™',
snippet: 'The Next, Next Generation tablet.'
}
];
}
});