2016-06-17 5 views
0

내가 구성 요소와 사이트 탐색을 구축 오전에 notyfing,이처럼은 각도 변화

class siteSectionController { 
    $onInit() { 
    const id = this.sectionId; 
    const title = this.sectionTitle; 
    this.o = { id, title }; 
    this.wrap.addSection(this.o); 
    } 
} 

app.component('siteSection', { 
    template, 
    transclude: true, 
    controller: siteSectionController, 
    bindings: { 
    sectionTitle: '@', 
    sectionId: '@' 
    }, 
    require: { 
    wrap: '^siteWrapper' 
    } 
}); 

나는 기본적으로 여기에서 각 섹션을 래퍼의 각 섹션에 등록하려고합니다. sections 어레이.

class siteMenuController { 
    $onInit() { 
    this.buildSections(this.wrap.sections); 
    } 

    buildSections(sections) { 
    Array.prototype.forEach.call(sections, s => { 
     console.log(s); 
    }); 
    } 
} 

app.component('siteMenu', { 
    controller: siteMenuController, 
    bindings: { 
    items: '<', 
    className: '@' 
    }, 
    template: template, 
    transclude: true, 
    require: { 
    wrap: '^siteWrapper' 
    } 
}); 

불행하게도, 비어 반환 지금은 sectionssite-menu에가 되었합니다. 즉, 이것은 너무 일찍 진행되고 있음을 의미합니다. 나는 단지 setTimeout을 던져서 할 수 있었지만 더 좋은 방법이 있다고 믿는다. $scope$broadcast/$emit을 생략하고 구성 요소가 어떻게 든 서로 이야기하기를 바랍니다.

어떻게해야합니까? 변수의 값은 예를 들어

을 변경 때마다 변수가 $ scope.newVar 경우

답변

0

당신이 실행됩니다 그 변수에 시계를 넣을 수 있습니다

당신은

$scope.$watch('newVar',function(newval,oldval){ 
//your code goes here 
}) 
+0

거기에 감시자를 넣을 수 있습니다 '$ scope'을 사용하고 싶지는 않습니다. 이것은 ng1.5에서 가장 좋은 방법은 아닙니다. –