官术网_书友最值得收藏!

Controllers and components in templates

AngularJS provides the ng-controller directive to attach a controller to the view and ties the view to the controller related to that view. Angular doesn't support the controller and the ng-controller directive to associate a controller to the view. The component agrees its associated view or template and not vice versa.

AngularJS:

<div ng-controller="PacktBooksCtrl as vm"> 

Angular:

@Component({ 
  selector: 'packt-books', 
  templateUrl:'app/packtbooks.component.html' 
})

In AngularJS, we define controllers using Immediately Invoked Function Expressions (IIFE). In Angular, we define components using TypeScript classes decorated with @Component, providing the metadata such as selector, templateUrl, and others.

AngularJS:

(function () { 
  ... 
}()); 

Angular:

@Component({ 
  selector: 'packt-books', 
  templateUrl:'app/packtbooks.component.html' 
}) 
export class PacktBooks { 
} 
主站蜘蛛池模板: 南昌市| 同德县| 巨鹿县| 开阳县| 富裕县| 勐海县| 新源县| 乌兰察布市| 岳普湖县| 临猗县| 长汀县| 德格县| 上高县| 永新县| 班戈县| 拉孜县| 沐川县| 郁南县| 连平县| 鄄城县| 仙居县| 库伦旗| 隆林| 息烽县| 松溪县| 关岭| 工布江达县| 徐汇区| 甘肃省| 商河县| 瑞丽市| 县级市| 德州市| 馆陶县| 新丰县| 黔东| 吉林市| 金华市| 富民县| 沭阳县| 梁平县|