this ng-book JSBin에서 $scope.$watch()
은 프로토 타입 상속으로 인해 $rootScope.$watch()
으로 해결됩니다.
$scope
이 컨트롤러 내부에 $rootScope
과 똑같이 삽입 될 수 있습니까? 프로토 타입 상속을 거치지 않고 컨트롤러 내에 있습니까?
참조를 위해 여기에 코드를 복제 :
// open this example and type person.name into the test field
angular.module('myApp', [])
.controller('MyController',
['$scope', '$parse', function($scope, $parse) {
$scope.person = {
name: "Ari Lerner"
};
$scope.$watch('expr', function(newVal, oldVal, scope) {
if (newVal !== oldVal) {
// Let's set up our parseFun with the expression
var parseFun = $parse(newVal);
// Get the value of the parsed expression, set it on the scope for output
scope.parsedExpr = parseFun(scope);
}
});
}]);
가 주입 될 수있다, 그것은되지 않습니다 '같은 $로 scope'하지만,'$의 scope' 여전히 루트 – charlietfl
ohkay 좋지만 방법의 자녀가 될 것인가? – Mahesha999