Я очень новичок в системе Angular JS и Ionic.Угловой JS- Ответ от webservice, не занесенный в список
services.js
В файле, в .factory
методе вебсервис вызывается и может показать предупреждение с ответом JSon, как показано на скриншоте ниже
Но представление списка не заполняется. Я попытался двумя способами.
Попробуйте 01:
Угловая JS код
angular.module('starter.services', [])
.factory('Chats', function($http) {
var chats;
return {
all: function() {
$http.get(url).
then(function(response) {
//alert(JSON.stringify(response.data.employee));
chats=response.data.employee;
alert(JSON.stringify(chats));
return chats;
}, function(error) {
alert(JSON.stringify(error));
});
return chats;
}
};
});
HTML5 код
<ion-view view-title="Chats">
<ion-content>
<ion-list>
<ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="chat in chats" type="item-text-wrap">
<img ng-src="http://findicons.com/files/icons/820/simply_google/256/google_android.png">
<h2>{{chat.employeeCode}}</h2>
<p>{{chat.createdBy}}</p>
<i class="icon ion-chevron-right icon-accessory"></i>
<ion-option-button class="button-assertive" ng-click="remove(chat)">
Delete
</ion-option-button>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
Попробуйте 2
В этой попытке я назначен chats
переменные в одном файл в следующем массив,
var chats = [{
id: 0,
name: 'Ben Sparrow',
lastText: 'You on your way?',
face: 'https://pbs.twimg.com/profile_images/514549811765211136/9SgAuHeY.png'
}, {
id: 1,
name: 'Max Lynx',
lastText: 'Hey, it\'s me',
face: 'https://avatars3.githubusercontent.com/u/11214?v=3&s=460'
}, {
id: 2,
name: 'Adam Bradleyson',
lastText: 'I should buy a boat',
face: 'https://pbs.twimg.com/profile_images/479090794058379264/84TKj_qa.jpeg'
}, {
id: 3,
name: 'Perry Governor',
lastText: 'Look at my mukluks!',
face: 'https://pbs.twimg.com/profile_images/3424/3j5HUXMY.png'
}, {
id: 4,
name: 'Mike Harrington',
lastText: 'This is wicked good ice cream.',
face: 'https://pbs.twimg.com/profile_images/578237281384841216/R3ae1n61.png'
}];
var chats = [{
id: 0,
name: 'Ben Sparrow',
lastText: 'You on your way?',
face: 'https://pbs.twimg.com/profile_images/514549811765211136/9SgAuHeY.png'
}, {
id: 1,
name: 'Max Lynx',
lastText: 'Hey, it\'s me',
face: 'https://avatars3.githubusercontent.com/u/11214?v=3&s=460'
}, {
id: 2,
name: 'Adam Bradleyson',
lastText: 'I should buy a boat',
face: 'https://pbs.twimg.com/profile_images/479090794058379264/84TKj_qa.jpeg'
}, {
id: 3,
name: 'Perry Governor',
lastText: 'Look at my mukluks!',
face: 'https://pbs.twimg.com/profile_images/3424/3j5HUXMY.png'
}, {
id: 4,
name: 'Mike Harrington',
lastText: 'This is wicked good ice cream.',
face: 'https://pbs.twimg.com/profile_images/578237281384841216/R3ae1n61.png'
}];
HTML5
<ion-view view-title="Chats">
<ion-content>
<ion-list>
<ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="chat in chats" type="item-text-wrap">
<img ng-src="https://pbs.twimg.com/profile_images/514549811765211136/9SgAuHeY.png">
<h2>{{chat.name}}</h2>
<p>{{chat.lastText}}</p>
<i class="icon ion-chevron-right icon-accessory"></i>
<ion-option-button class="button-assertive" ng-click="remove(chat)">
Delete
</ion-option-button>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
Попробуйте 2 работают так же, как я назначил жёстко прописанный массив JSON переменный. Но, Попробуйте 1 не работает.
UPDATE:
controller.js
angular.module('starter.controllers', [])
.controller('DashCtrl', function($scope) {})
.controller('ChatsCtrl', function($scope, Chats) {
$scope.chats = Chats.all();
})
/*.controller('ChatDetailCtrl', function($scope, $stateParams, Chats) {
$scope.chat = Chats.get($stateParams.chatId);
})*/
.controller('AccountCtrl', function($scope) {
$scope.settings = {
enableFriends: true
};
});
Пожалуйста, помогите мне найти решение.
Где ваш код контроллера? Вы не можете напрямую получить доступ к заводским значениям из своего вида без контроллера – Tom
за одну минуту. Я обновлю –
См. Обновленное сообщение –