首页 > Web开发 > 详细

[AngularJS] New in Angular 1.3 - bindToController

时间:2014-12-25 21:51:44      阅读:290      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/Answer1215/p/4185504.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!