瀏覽代碼

allow $parent/$root access on $scope

Evan You 11 年之前
父節點
當前提交
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