码迷,mamicode.com
首页 > Web开发 > 详细

web -- Angularjs 笔记2

时间:2015-11-26 10:57:34      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

<body ng-app="myApp">
    <p>多个控制器</p>
    <div ng-controller="Ctrl1">
        <p>{{greeting.text}}, Angular</p>
    </div>
    <div ng-controller="Ctrl2">
        <p>{{greeting.text}}, Ctrl2</p>
        <p>{{program.text}}, program</p>
    </div>
    <script src="js/angular-1.3.0.js"></script>
    <script>
        /*
        function Ctrl1($scope, $rootScope){
            $scope.greeting = { text:"Hello" }
            $rootScope.program = { text:"angularjs" };
        }
        function Ctrl2($scope){
            $scope.greeting = {text:"Good morning"};
        }
        */
        var app = angular.module("myApp", []);
        app.controller("Ctrl1", function($scope, $rootScope){
            $rootScope.greeting = { text:"Hello" };
        });
        app.controller("Ctrl2", function($scope){
            $scope.program = { text:"text2" };
        });
    </script>
</body>

web -- Angularjs 笔记2

标签:

原文地址:http://www.cnblogs.com/lianfu/p/4996807.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!