What I need to do?
I am trying to load the "ion-checkbox ng-repeat"
"onDeviceReady"
automatically at the time of page load. Below is the HTML code.
<ion-checkbox ng-repeat="item in devList"
ng-model="item.checked"
ng-checked="item.checked">
{{ item.text }}
</ion-checkbox>
But the "ion-checkbox ng-repeat"
is getting loaded only when click event is triggered.
The below is the angular-js code which needs to be triggered automaticlly at the time of page load.
Problem: The data for "ion-checkbox ng-repeat" is not getting filled at the time of page load. Can anyone help to solve the issue.
angular.module('app', ['ionic'])
.controller('AppCtrl', function($scope) {
$scope.devList = [];
window.addEventListener("deviceready", onDeviceReady, true);
function onDeviceReady() {
var options = new ContactFindOptions();
options.filter = ""; // empty search string returns all contacts
options.multiple = true; // return multiple results
filter = ["*"]; // return contact.displayName field
//document.getElementById("lan").innerHTML = lan;
// find contacts
navigator.contacts.find(filter, onSuccess, onError, options);
}
function onSuccess(contacts) {
for (var i = 0; i < contacts.length; i++) {
$scope.devList[i] = {text:""+contacts[i].name.formatted, emails:{email:""+contacts[i].emails[0].value,checked:false}, phno:{phone:""+contacts[i].phoneNumbers[0].value,checked:false},addres:{address: contacts[i].addresses||[],checked:false},checked: false};
$scope.emails[i] = {email:""+contacts[i].emails[0].value+""};
}
}
function onError(contactError) {
alert('onError!');
}
}
You need to call $apply if you do anything outside of angular context
function onSuccess(contacts) {
for (var i = 0; i < contacts.length; i++) {
$scope.devList[i] = {text:""+contacts[i].name.formatted, emails:{email:""+contacts[i].emails[0].value,checked:false}, phno:{phone:""+contacts[i].phoneNumbers[0].value,checked:false},addres:{address: contacts[i].addresses||[],checked:false},checked: false};
$scope.emails[i] = {email:""+contacts[i].emails[0].value+""};
$scope.$apply();
}
}