angularjs 控制器 作用域 有继承
<body ng-app="myapp">
<div ng-controller = "firstController">
{{name}} //“张三”S
{{age}} //不能访问 :如果secondController 有 $rootScope 就可以访问到。
<div ng-controller = "secondController">
{{name}} //"张三" 继承了 name 属性;“张三”
{{age}} //"30"
</div>
</div>
</body>
<script>
var app =angular.moudle("myapp",[]);
app.controller("firstController",function($scope){
$scope.name="张三";
})
app.controler("secondController",function($scope){
$scope.age = 30;
})
</script>
时间: 2024-11-05 03:41:08