Angular:将所选项目传递给其他选择框

时间:2017-06-08 14:49:56

标签: html angularjs mean

我正在MEAN上建立一个网站,我有2个页面,我希望从一个页面中选择一个值在另一个页面中使用。两个页面都有相同的选择框,但我希望在单击<a href>项目

时进行更改

这是您可以选择城市名称的第一页:此城市名称正在整个页面上使用

<div  ng-controller="DataCtrl" ng-init="city()">
   <div class="title-1">Seach on city</div>
      <select ng-model="selectedItem" ng-options="item as item.city for item in items"></select>

   <div class="title-1">Central heating problems in {{selectedItem.city}}</div>
      <p>If you want to look for plumbers in {{selectedItem.city}}, click <a href="/search-plumber">here</a></p>
</div>

这是第二页

<div  ng-controller="DataCtrl" ng-init="city()">
   <div class="title-1">Seach on city</div>
     <select ng-model="selectedItem" ng-options="item as item.city for item in items"></select>

   <div class="title-1">Plumbers in {{selectedItem.city}}</div>
     <p>You have selected Plumbers in {{selectedItem.city}}</p>
</div>

现在,当点击<a href>时,我想将所选的城市名称传递给要在那里使用的其他页面。

这是我从数据库中获取数据的控制器

app.controller('DataCtrl', function($scope,$http){

  $scope.city = function(){
  $scope.items = [];

  $http.get('/getdata').then(function(d){
    $scope.items = d.data;
    $scope.selectedItem = $scope.items[0];
  },function(err){
  console.log(err);
  });
};

0 个答案:

没有答案