فهرست منبع

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
   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
   // relay change events that sent down from
   // the scope prototype chain.
   // the scope prototype chain.
   var ob = this._observer
   var ob = this._observer