0
我很新手開發一個Angular應用程序。角度控制器不顯示數據
我有兩個觀點:
- 主營:搜索元素。
- 結果:顯示查詢結果。
搜索表單處於視圖中,並且它包含在兩個(主要和結果)視圖中。兩個視圖都鏈接到同一個控制器。
問題是當我在主視圖中單擊搜索時,服務被調用並返回值,但結果不顯示在結果視圖中。
如果我在結果視圖中執行相同的查詢,則一切正常,並顯示結果。
的代碼:
主視圖和結果包括完全相同seacher視圖:
<div ng-include src="'partials/boat-searcher.html'" class="text-center"></div>
搜索器視圖:
<input type="text" ng-model="departure" typeahead="suggestion for suggestion in cities($viewValue)" class="input-xlarge input-height-large" placeholder="Salida" autocomplete="off">
我的應用程序:
angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'myApp.controllers']).
config(['$routeProvider', '$httpProvider', function($routeProvider, $httpProvider) {
$routeProvider.when('/home', {templateUrl: 'partials/home.html', controller: 'BoatListCtrl'});
$routeProvider.when('/option-list', {templateUrl: 'partials/option-list.html', controller: 'BoatListCtrl'});
}]);
我的控制器:
.controller('BoatListCtrl', function BoatListCtrl($scope, $location, $routeParams, $http, Boat, Equipment, Extra) {
// Departures typeahead
$scope.departure = undefined;
$scope.cities = function(cityName) {
return $http.get("http://localhost:3000/departures?query="+cityName).then(function(response){
var names = response.data.map(function (source) { return source.name; });
return names;
});
};
// Gets options (boats)
$scope.getOptionList = function(departure, fechaSalida, fechaLlegada, personas) {
$scope.boats = Boat.query({departure: departure, fechaSalida: fechaSalida, fechaLlegada: fechaLlegada, personas: personas});
$location.path('/option-list');
};