0
進入一個參數對象服務在我的index.html我有這樣的:
<input type="text" ng-model="title" placeholder="Search..." >
<button type="submit" href="#" ng-click="getSearch()">Submit</button>
<select ng-model="selected" ng-options="obj.val as obj.display for obj in things"></select>
和我的控制器:
$scope.getSearch = function(){
svc.search($scope.selected)
.then(function(response){
$scope.searchData = response;
});
};
$scope.things = [
{display: 'Movie',
val: {s: $scope.title}},
{display: 'Series',
val: 'series'},
{display: 'Epsiode',
val: 'episode'},
];
最後我服務:
this.search = function(params){
return $http.get('http://www.omdbapi.com/',params)
.then(function(response) {
var results = response.data.Search;
return results;
});
};
好吧,看起來像我差點把它的工作。現在,它的全部工作除了似乎omdbapi不喜歡&編碼的參數。
$scope.getSearch = function(){
svc.search($scope.selected())
.then(function(response){
$scope.searchData = response;
});
};
$scope.things = [
{display: 'Movie',
val: function(){return {'type=movie&s': $scope.title};}},
{display: 'Series',
val: function(){return {'type=series&s': $scope.title};}},
{display: 'Epsiode',
val: function(){return {'type=episode&s': $scope.title};}},
];
而且我們有答案!當然,一旦我發佈了,我想清楚了......一直工作太久。
val: function(){return {type: 'movie',s: $scope.title};}},
你喜歡不喜歡,如果我從下拉菜單和類型的電影名稱在文本框中選擇電影,因此將搜索電影類型化的文字嗎? –
是的,這是我想要做的。 – user1490202
你有兩個json是分開還是單個json? –