scope的作用域及继承

<div class="col-xs-12" ng-controller="test">
        <p>test控制器</p>
        <p>ary: {{ary}}</p>
        <p>str: {{str}}</p>
        <div ng-controller="child">
          <P>child控制器</P>
          <input ng-model="ary" ng-list="">
          <p>子ary:{{ary}}</p>
          <input ng-model="str">
          <p>子str:{{str}}</p>
        </div>
      </div>
    app.controller("test",["$scope",function ($scope) {
      $scope.ary = ["qwe","adad"];
      $scope.str= "asda";
    }]);
    app.controller("child",["$scope",function ($scope) {

    }])



只是继承,不改变父作用域的值


<div class="col-xs-12" ng-controller="test">
        <h1><%= title %></h1>
        <p>test控制器</p>
        <p>ary: {{ary}}</p>
        <p>ary01: {{ary01}}</p>
        <p>str: {{str}}</p>
        <div ng-controller="child">
          <P>child控制器</P>
          <input ng-model="$parent.ary" ng-list="">
          <p>子ary:{{ary}}</p>
          <input ng-model="ary01.as" ng-list="">
          <p>子ary:{{ary01}}</p>
          <input ng-model="$parent.str">
          <p>子str:{{str}}</p>
        </div>
      </div>
    app.controller("test",["$scope",function ($scope) {
      $scope.$watch("test",function (newvalue) {
        console.log(newvalue);
      })
      $scope.ary = ["qwe","adad"];
      $scope.ary01 = {as:["qwe","adad"]};
      $scope.str= "asda";
    }]);
    app.controller("child",["$scope",function ($scope) {

    }])



继承并修改


总结:当你检索字面值时,原型链并不起作用。如果test也同时被更新的话,检索原型链是必须的;但如果值是一个对象,这就会发生。(记住,在Javascript中,函数、数组和对象都是对象)



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值