搜索
您的当前位置:首页正文

菜鸡学AngularJS 09 控制器 -继承方式通信-

来源:知库网

控制器的继承方式通信。

PS:继承方式需要把子控制器放在主控制器的controller内包含进去,然后就会从上到下开始继承。

如:下面的TestCall2的name就是继承自TestCall1的name里的值。

<!doctype html>
<html ng-app = "myapp">
<head>
<script 
</head>
<body>
<div ng-controller = "TestCall1">
    <p>{{one}}</p>
    <h1>{{name}}</h1>

    <div ng-controller = "TestCall2">
        <p>{{two}}</p>
        <h1>{{name}}</h1>
    </div>
</div>


</body>
<script>
var app = angular.module('myapp', []);
app.controller("TestCall1", function($scope){
    $scope.one = "第一个默认值";
    $scope.name = "需要继承的";

});
app.controller('TestCall2',  function($scope){
    $scope.two = "第二个默认值";
});
</script>
</html>
Top