控制器的继承方式通信。
PS:继承方式需要把子控制器放在主控制器的controller内包含进去,然后就会从上到下开始继承。
如:下面的TestCall2的name就是继承自TestCall1的name里的值。
<!doctype html>
<html ng-app = "myapp">
<head>
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></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>
网友评论