首页 > 代码库 > [AngularJS] New in Angular 1.3 - bindToController
[AngularJS] New in Angular 1.3 - bindToController
If you want to use controllers, instead of a link function, you can use bindToController.
<!DOCTYPE html><html ng-app="app"><head> <title>Egghead.io Tutorials</title> <style>body{padding:20px}</style> <link rel="shortcut icon" href="favicon.ico"> <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"> <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular.js"></script> <script src="app.js"></script></head><body><note message="hello"></note></body></html>
angular.module("app", []) .directive("note", function note() { return { scope: { message: "@" //pass in a string }, bindToController: true, controller: "NoteCtrl as note", template: "<div>{{note.message}}</div>" }; }) .controller("NoteCtrl", function NoteCtrl() { var note = this; });
[AngularJS] New in Angular 1.3 - bindToController
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。