문제 설명
ionic, 팝오버 범위에 범위 변수 전달 (ionic, pass scope variable to popover scope)
뷰 범위($scope.sort)에서 팝오버 범위로 변수를 전달하고 싶습니다. 팝오버에 설정되면 변수는 문제 없이 '나갑니다'. 아래 코드는
$scope.closeSortPopover`에 있습니다.
팝오버 범위가 컨트롤러의 범위입니다. 하지만 그렇지 않은 것 같습니다. 팝오버 범위는 어디에 있습니까? 여기에서 올바르게 이해한다면 팝오버 범위는 컨트롤러 범위의 자식입니다. 어떻게 액세스할 수 있습니까... ?
참고로 내 팝오버는 기본 보기의 큰 목록에 대해 다른 정렬 옵션을 제공하는 목록입니다. .
html:
참조 솔루션
방법 1:
In the controller js, you are assigning the scope of the controller to the scope of the popover. Thus all the methods in the controller scope are accessible via the popover view. In other words, both the controller view and popover view share the same scope.
In fact you might think this a violation of mvc as one controller cannot own two views, but with angular, you actually can't otherwise.
To create isolated scope, your only option is directives.
방법 2:
I discovered that due to javascript inheritence, the scope variable must be contained into an object to be passed to inherited scopes.
So instead of this:
$scope.sort = ....
I declared this in my controller:
$scope.data={};
$scope.data.sort = ....
and used in my html (both in the initial view and in the popover templates):
data.sort
Documented here apparently: https://github.com/angular/angular.js/wiki/Understanding‑Scopes#javascript‑prototypal‑inheritance
(by Louis、Lakmal Caldera、Louis)