Ionic - 如何使用$ ionicHistory.goBack()检测并将值传递回原始视图; [英] Ionic - How to detect and pass value back to original view with $ionicHistory.goBack();

查看:4500
本文介绍了Ionic - 如何使用$ ionicHistory.goBack()检测并将值传递回原始视图;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用离子,我想有一个用例从列表中选择并返回到具有一些价值的原始视图。我已经做了大部分的部分,除了检测它已经返回到原来的视图,并传递一个值回到原来的视图。



到目前为止,已完成:

 < button class =button button-block button-outline button-positiveng-click =performselectUnit()>选择单位
< / button>

这是使用列表进入新视图的触发器

  $ scope.performselectUnit = function(){
console.log('performselectUnit');

$ state.go('app.units');当按下对所选行执行操作时,
}

>

 < ion-item collection-repeat =unit in unitsclass =item item-icon-right item-icon-left ng-click =selectUnit(unit.id)> 

选择返回原始视图的行$ ionicHistory.goBack()

  $ scope.selectUnit = function(unit_id){
console.log('performselectUnit:'+ unit_id);

$ ionicHistory.goBack();
}

从最后一个函数,如何检测它回到原来的视图,传递一些值。



谢谢。



更新:
我试过了。

广播结果

  $ scope.selectUnit = function(unit_id){
console.log('performselectUnit:'+ unit_id);

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


}

事件和结果。

  $ rootScope。$ on('selected-unit',function(event,args){
console.log(received selected-unit+ args.data);
$ scope.showSelectedUnit = args.data;
});

但它从未在视图中更新

 < label class =item item-text-wrap> 
< button class =button button-block button-outline button-positiveng-click =performselectUnit()>选择单位
< / button>
{{showSelectedUnit}}
< / label>

如何在视图中更新?或者有更好的方法

解决方案

面对同样的问题,我可以通过切换呼叫的顺序goBack和广播:

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


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

    <button class="button button-block button-outline button-positive" ng-click="performselectUnit()"> Select Unit
    </button>

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

  <ion-item collection-repeat="unit in units" class="item item-icon-right item-icon-left" ng-click="selectUnit(unit.id)">

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

<label class="item item-text-wrap">
    <button class="button button-block button-outline button-positive" ng-click="performselectUnit()"> Select Unit
    </button>
    {{showSelectedUnit}}
</label>

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();

这篇关于Ionic - 如何使用$ ionicHistory.goBack()检测并将值传递回原始视图;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆