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

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 { 
} 
主站蜘蛛池模板: 邻水| 神木县| 当雄县| 徐水县| 肥东县| 安新县| 花垣县| 治县。| 株洲市| 麻阳| 开江县| 灯塔市| 靖远县| 莱西市| 富平县| 晋中市| 黔江区| 承德市| 自贡市| 霍州市| 永胜县| 永清县| 林甸县| 田东县| 攀枝花市| 苏州市| 柳江县| 灵台县| 财经| 淮安市| 安溪县| 北票市| 棋牌| 古交市| 平凉市| 会东县| 南乐县| 吉安县| 突泉县| 香格里拉县| 乌什县|