AngulatJS Controller

AngulatJS Controller
<!DOCTYPE html>

<html ng-app="demo">
<head>
    <title></title>
</head>
<body>
    <input type="text" ng-model="data.message" />
    <h1>{{data.message}}</h1>
    <div ng-controller="firstCtl">
        <input type="text" ng-model="data.message" />
        <h1>{{data.message}}</h1>
    </div>
    <div ng-controller="secondCtl">
        <input type="text" ng-model="data.message" />
        <h1>{{data.message}}</h1>
    </div>
</body>
<script src="angular.min.js" type="text/javascript"></script>
<script>
    var demo = angular.module("demo", []);
    demo.controller("firstCtl", function ($scope) {
        $scope.data = {message:"JACKEY"};
    });
    demo.controller("secondCtl", function ($scope) {
        $scope.data = { message: "cSSI" };
    });
</script>

</html>
AngulatJS Controller

AngulatJS Controller

这个例子给我的认识是:

没有声明在controller里面的全局message会对声明在controller里面的message产生影响,

firstCtl不对secondCtl产生影响

AngulatJS Controller,布布扣,bubuko.com

AngulatJS Controller

上一篇:MVC设计模式


下一篇:最简单的ajax调用webservice