문제

부모 범위를 지정한 모든 하위 범위 목록을 얻는 방법을 알고 싶습니다.스코프의 속성에서 찾을 수있는 모든 것은 $$ Childhead, $$ childtail, $$ NextBling 및 $$ Prevsibling입니다.

이제 사용하고있는 접근법은 부모의 자식 헤드를 가져온 다음 NextSibling이 null이 될 때까지 다음 아이를 얻으려면 다음 자식을 얻는 것입니다.

더 나은 접근이 있습니까? 모든 아이들에게 메소드 [GetModel]를 호출하고 싶다는 것을 감안할 때, 다시이 작업을 수행하는 더 좋은 방법이 있습니까?

도움이 되었습니까?

해결책

자식 지시문은 분리 된 범위를 사용하고 있으며 부모가 보이지 않는 자체 값을 사용합니다. 부모 범위 에서이 값에 액세스하고 싶습니다.

"하위 범위에 액세스가 필요한 부모 범위"의 문제를 해결하는 '각도'는 모델을 상위로 이동하고 하위 범위가 상위 등록 정보 / 데이터를 참조하는 것입니다 (하위 범위가 아닌) 자신의 로컬 속성 / 사본을 가지고 있음). 예를 들어, 각 반복에 입력 양식 요소 (즉, 각 반복이 필요함)를 포함하는 경우 NG- 반복을 처리하는 방법은 다음과 같습니다. NG-MODEL, NG-REPEAT 및 Inputs의 난이도 지시문이있는

는 먼저 상위 범위에서 객체 배열을 정의한 다음 격리 된 자식 범위가 '='표기법 (즉, 양방향 데이터 인 디지털 표기법)을 사용하여 상위 범위 어레이 (또는 개별 오브젝트)에 액세스하게됩니다. 객체가 공유되고 있기 때문에 격리 된 범위는 상위 객체를 참조합니다 (로컬 복사본을 얻지 못함). 이제 하위 범위에서 변경 한 사항 속성은 실제로 상위 범위 속성을 변경합니다.

다른 팁

모든 각도 범위는 DOM 요소에 첨부되며 현재 요소를 사용하여 자식을 검사 할 수있는 자식을 사용하여 시작할 수 있습니다.일단 아래에서 아래 기능을 사용하여 범위를 얻습니다.

angular.element('#5th_element').scope();
.

Angularjs 1.3.2에서는 NGMock 모듈에 countChildScopes 메소드가 추가되었습니다.

/**
* @ngdoc method
* @name $rootScope.Scope#$countChildScopes
* @module ngMock
* @description
* Counts all the direct and indirect child scopes of the current scope.
*
* The current scope is excluded from the count. The count includes all isolate child scopes.
*
* @returns {number} Total number of child scopes.
*/
function countChildScopes(scope) 
  {
  // jshint validthis: true
  var count = 0; // exclude the current scope
  var root = scope || angular.element(document).injector().get('$rootScope');
  var pendingChildHeads = [root.$$childHead];
  var currentScope;

  while (pendingChildHeads.length) 
    {
    currentScope = pendingChildHeads.shift();

    while (currentScope) 
      {
      count += 1;
      pendingChildHeads.push(currentScope.$$childHead);
      currentScope = currentScope.$$nextSibling;
      }
    }

  return count;
  }
.

객체를 반환 값으로 사용하여 ID를 가져옵니다.

function enumerateChildScopes(scope) 
  {
  // jshint validthis: true
  var enum = {}; // exclude the current scope
  var root = scope || angular.element(document).injector().get('$rootScope');
  var pendingChildHeads = [root.$$childHead];
  var currentScope;

  while (pendingChildHeads.length) 
    {
    currentScope = pendingChildHeads.shift();

    while (currentScope) 
      {
      enum["scope"+pendingChildHeads.length] = currentScope.$id;
      pendingChildHeads.push(currentScope.$$childHead);
      currentScope = currentScope.$$nextSibling;
      }
    }

  return enum;
  }
.

참고 문헌

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top