=====Связывание одного свойства с асинхронными данными=====
Чтоб эмулировать асинхронность используем setTimeout
Selected:
app.controller('DemoCtrl', function ($scope, $http, $timeout, $interval) {
var vm = this;
vm.personAsync = {selected : "wladimir@email.com"};
vm.peopleAsync = [];
$timeout(function(){
vm.peopleAsync = [
{ name: 'Adam', email: 'adam@email.com', age: 12, country: 'United States' },
{ name: 'Amalie', email: 'amalie@email.com', age: 12, country: 'Argentina' },
{ name: 'Estefanía', email: 'estefania@email.com', age: 21, country: 'Argentina' },
{ name: 'Adrian', email: 'adrian@email.com', age: 21, country: 'Ecuador' },
{ name: 'Wladimir', email: 'wladimir@email.com', age: 30, country: 'Ecuador' },
{ name: 'Samantha', email: 'samantha@email.com', age: 30, country: 'United States' },
{ name: 'Nicole', email: 'nicole@email.com', age: 43, country: 'Colombia' },
{ name: 'Natasha', email: 'natasha@email.com', age: 54, country: 'Ecuador' },
{ name: 'Michael', email: 'michael@email.com', age: 15, country: 'Colombia' },
{ name: 'Nicolás', email: 'nicole@email.com', age: 43, country: 'Colombia' }
];
},3000);
}
Шаблон вывода
{{ctrl.personAsync.selected | json }}
List Count:
{{ (ctrl.peopleAsync || []).length }}
Data will be populated in 3 secs
{{:angular:angularjs:сторонние_модули:ui.select2:select21.png |}}