从选择另一种观点Angular.js通价值 [英] Angular.js pass value from select to another view

查看:120
本文介绍了从选择另一种观点Angular.js通价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一些选择的值传递给另一个观点。这是我的HTML。有一个选择字段。在按钮点击下一页应与选择的值作为标题标题显示出来。

 < D​​IV CLASS =清单>
  <标签类=逐项输入项选>
    < D​​IV CLASS =输入标签>
      可待因施塔特
    < / DIV>
    <选择NG模型=selectedCityNG选项=city.name城市在城市>    < /选择>
  < /标签>
< / DIV>< BR>
<按钮NG点击=searchCity(selectedCity)级=按钮,按钮的轮廓按钮呈阳性>
  Gutscheine俗尘
< /按钮>

控制器:

  .controller('AccountCtrl',函数($范围,$州){
    $ scope.cities = [
      {ID:001,名称:康斯坦茨},
      {ID:002,名称:弗莱堡}
    ];
    $ scope.selectedCity = $ scope.cities [0];    $ scope.searchCity =功能(selectedCity){
        的console.log(selectedCity.name);
        $ state.go(tab.friends);
    };
});

在执行console.log(selectedCity.name)工作正常。但我怎么可以把这个值到另一个控制器,以显示它的头?我不需要的服务! TY。

更新:那里的标题应显示的视图:

 <离子视图标题={{selectedCity.name}}>
< /离子视图>

第二种观点的控制器:

  .controller('FriendsCtrl',函数($范围){})


解决方案

您可以传递值作为路由PARAMS到另一种观点,如果提供另一种观点指出了一些其他的途径。

在您的routes.js,你可以把它像的viewName /:paramName配置

然后在你的控制器,你可以像$ routeParams.paramName ..

访问

[paramName而你传递参数的名称:D]

I want to pass some selected value to another view. This is my HTML. There is a select field. On Button click the next page should be shown with the selected value as header title.

<div class="list">
  <label class="item item-input item-select">
    <div class="input-label">
      Deine Stadt
    </div>
    <select ng-model="selectedCity" ng-options="city.name for city in cities">

    </select>
  </label>
</div>

<br>
<button ng-click="searchCity(selectedCity)" class="button button-outline button-positive">
  Gutscheine suchen
</button>

The Controller:

.controller('AccountCtrl', function($scope, $state) {
    $scope.cities = [
      {id:'001', name:'Konstanz'},
      {id:"002", name:"Freiburg"} 
    ];
    $scope.selectedCity = $scope.cities[0];

    $scope.searchCity = function(selectedCity){
        console.log(selectedCity.name);
        $state.go("tab.friends");
    };
});

The console.log(selectedCity.name) works fine. But how can I bring this value to another controller to show it in header? I don´t need a service! Ty.

UPDATE: The VIEW where the title should be shown:

<ion-view title="{{selectedCity.name}}">
</ion-view>

The Controller of the second view:

.controller('FriendsCtrl', function($scope) {

})

解决方案

You can pass the value as a route params to the other view, provided if the other view points to some other route..

in your routes.js, you can put it like viewName/:paramName.

And then in your controller, you can access it like $routeParams.paramName..

[paramName is the name of the parameter you're passing :D]

这篇关于从选择另一种观点Angular.js通价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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