Using ionic, I am trying to have a use case to select from a list and return back to the original view with some value. I'ved already done most of the part except detecting it has returned to the original view and passing a value back to the original view.

Here's so far what i'ved accomplished:

button that goes to a list

Select Unit

this is the trigger to go to the new view with the list

$scope.performselectUnit = function(){

console.log('performselectUnit');

$state.go('app.units');

}

the view with list when press performs an action on the selected row

on selection of the row it goes back to the original view with $ionicHistory.goBack()

$scope.selectUnit = function(unit_id){

console.log('performselectUnit:' + unit_id);

$ionicHistory.goBack();

}

From the last function, how do detect its gone back to the original view and pass some value.

Thanks.

UPDATE:

I tried this.

Broadcast the result

$scope.selectUnit = function(unit_id){

console.log('performselectUnit:' + unit_id);

$ionicHistory.goBack();

$rootScope.$broadcast('selected-unit', { data: unit_id });

}

in the original view controller i capture the event and result.

$rootScope.$on('selected-unit', function(event, args) {

console.log("received selected-unit" + args.data);

$scope.showSelectedUnit = args.data;

});

but it NEVER got updated in the view

Select Unit

{{showSelectedUnit}}

How can I get it to update in the view ? or is there a better way

解决方案

Faced to the exact same issue, I could make it work by switching the order of calls to goBack and broadcast:

$rootScope.$broadcast('selected-unit', { data: unit_id });

$ionicHistory.goBack();

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐