我想将一些选定的值传递给另一个视图。这是我的HTML。有一个选择字段。在“按钮”上单击,应显示下一页,并将所选值作为标题。
<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>
控制器:
.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");
};
});
console.log(selectedCity.name)运行正常。但是,如何将这个值带到另一个控制器以在标头中显示呢?我不需要服务!泰
更新:应在其中显示标题的VIEW:
<ion-view title="{{selectedCity.name}}">
</ion-view>
第二个视图的控制器:
.controller('FriendsCtrl', function($scope) {
})
最佳答案
您可以将该值作为路径参数传递给另一个视图,前提是该其他视图指向某个其他路由。
在您的routes.js中,您可以像viewName /:paramName这样放置它。
然后在您的控制器中,您可以像$ routeParams.paramName一样访问它。
[paramName是您要传递的参数的名称:D]