ionic, 팝오버 범위에 범위 변수 전달 (ionic, pass scope variable to popover scope)


문제 설명

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 LouisLakmal CalderaLouis)

참조 문서

  1. ionic, pass scope variable to popover scope (CC BY‑SA 2.5/3.0/4.0)

#ionic #angularjs






관련 질문

Cordova - OS 업그레이드 후 iOS/Android 모두에서 앱 충돌 (Cordova - app crashes on both iOS/Android after an OS upgrade)

모바일용 HTML 5의 특정 영역에 링크가 있는 이미지 (Image with links in certain areas in HTML 5 for mobile)

Play 스토어에서 오류 발생 - "이 앱은 모든 기기와 호환되지 않습니다." (Getting error from play store - “This app is incompatible with all of your devices.”)

div의 오른쪽 하단에 이온 버튼 정렬 (Align an ionic button at the bottom right of a div)

새로운 Xcode 프로비저닝 정책 및 Ionic Framework (New Xcode provisioning policy and Ionic Framework)

각도 [$injector:unpr] 알 수 없는 공급자 오류를 해결하는 방법? (How to solve angular [$injector:unpr] Unknown provider error?)

ionic, 팝오버 범위에 범위 변수 전달 (ionic, pass scope variable to popover scope)

Angular: 2필드 데이터 바인딩 문제 (Angular: issue with two-field data binding)

ionic 2에서 ion-title의 글꼴 색상 변경 (Change font color of ion-title in ionic 2)

PhoneGap 빌드가 내 모든 파일을 업데이트하지 않습니다. (PhoneGap build is not updating all of my files)

Ionic 빌드 Android를 수행하는 동안 오류가 발생했습니다. (Error while doing Ionic build android)

$ionicHistory.backView() stateParams 변경 후 돌아가기 (Going back after changing stateParams of $ionicHistory.backView())







코멘트