Просмотр исходного кода

allow $parent/$root access on $scope

Evan You 11 лет назад
Родитель
Сommit
7b142af05a
1 измененных файлов с 15 добавлено и 0 удалено
  1. 15 0
      src/instance/scope.js

+ 15 - 0
src/instance/scope.js

@@ -23,6 +23,21 @@ exports._initScope = function () {
 
   if (!parent) return
 
+  // scope parent accessor
+  Object.defineProperty(scope, '$parent', {
+    get: function () {
+      return parent.$scope
+    }
+  })
+
+  // scope root accessor
+  var self = this
+  Object.defineProperty(scope, '$root', {
+    get: function () {
+      return self.$root.$scope
+    }
+  })
+
   // relay change events that sent down from
   // the scope prototype chain.
   var ob = this._observer