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

  • Expert Angular
  • Mathieu Nayrolles Rajesh Gunasundaram Sridhar Rao
  • 111字
  • 2021-07-15 17:05:37

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 { 
} 
主站蜘蛛池模板: 石柱| 德州市| 杨浦区| 江安县| 拉孜县| 云浮市| 商都县| 淅川县| 图片| 那坡县| 宽城| 枞阳县| 田林县| 凭祥市| 商都县| 本溪市| 抚州市| 砀山县| 铁力市| 阿拉善盟| 交口县| 台中市| 乌兰浩特市| 石屏县| 大渡口区| 开平市| 团风县| 临沭县| 贡山| 绥芬河市| 桐乡市| 河西区| 湟中县| 开化县| 天等县| 罗城| 岗巴县| 锡林郭勒盟| 阿克苏市| 溆浦县| 时尚|