how angular controller (and scope) inheritance works

前端 未结 3 1702
梦谈多话
梦谈多话 2020-12-12 03:49

I\'m trying to figure out how controller inheritance works. I have three controllers:

var myApp = angular.module(\'app\', []);

myApp.controller(\'MainContro         


        
3条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 04:19

    If you want to overwrite name property in child scopes ,convert your primitive name property into object.

    $scope.user = {};
    $scope.user.name='main';
        $scope.getName = function() {
            return $scope.user.name;
        };
    

    And you should read https://github.com/angular/angular.js/wiki/Understanding-Scopes for detailed information.

提交回复
热议问题