PHPファイルから犬の品種リストを返すファクトリを作成していますが、コントローラに応答データを返すことはできません。私は工場HTTPリクエスト後に工場からコントローラにデータを返すAngularJS
angular.module('myApp')
.factory('DataService, function($http) {
return {
get_breeds: function() {
method: 'GET',
url: 'http://localhost:8080/php/api/getbreeds.php'
}).then(function onSuccess(response) {
console.log(response); // responds with 200
return response.data;
}).catch(function onError(err) {
console.log(err);
})
}
}
});
としてこれを持っており、これが私のコンポーネント
angular.module('myApp')
.component('homeComponent', {
templateUrl: 'home.component.html,
controller: function (DataService) {
DataService.get_breeds()
.then(function(response) {
var dog_breeds = response;
console.log(dog_breeds)
});
...
の一部であり、しかし、私は戻っ何でも、エラーメッセージが届きません。誰かが正しい方向に私を導くことができますか?
誤ってコピーして貼り付けた場合はわかりませんが、この行は 'templateUrl: 'home.component .html、 'は閉じた一重引用符がありません – user2340824
Ahhhええ、それは悪いc&pエラーでした! –
'getBreeds'で' Promise'を返すことを意味しましたか?関数が正しく表示されない場合は、シンタックスハイライトも混乱します。または、 'getBreeds'に' $ http'を注入した場所はどこですか? – sabithpocker