AngularJS--組件化<component>
var app=angular.module("pageHeader",[]);
app.component("組件名字",{
template:"<h1>歡迎您尊敬的用戶</h1>"
})
<page-header></page-header>
注意:組件命名規則
組件的命名有框架自己的規則和使用規範,都是根據實際項目需要進行封裝處理的
組件命名規則:駝峯命名法,見名知意,如:myComp
使用規則:W3C命名規則,將大寫字母轉換成小寫字母,前面加中劃線;
controller:組件控制器
代碼:定義組件語法使用var app=angular.module("myapp",[]);
app.component("pageHeader",{
template:"<h1>歡迎您尊敬的用戶{{username}}</h1>",
templateUrl:"需要打開的頁面路徑",
controller:function($scope){
$scope.username="Tom"}
})