Hello All,
I am newbie in angular js and ionic framework.
I am trying to create some variables in service/factory and try to add data in to those variables from controllers. I am getting error on below code. Can anybody please help me.
pmApp.service('DataService', function () {
var selection = [];
var selection1 = [];
var jsonData = {};
var jsonTrackedData = {};
DataService.setSelectedData = function (value) {
selection.push(value);
};
DataService.setTrackedData = function (value) {
selection1.push(value);
};
DataService.getTrackedData = function () {
return selection1;
}
DataService.getSelectedData = function () {
return selection;
}
return DataService;
});
pmApp.controller('CheckboxController', function ($scope, DataService) {
$scope.devList = [{
text: "Device & app history",
details: "Allows the app to view one or more of: information about activity on the device, which apps are running, browsing history and bookmarks",
checked: true
}, {
text: "Identity",
details: "Uses one or more of: accounts on the device, profile data",
checked: false
}, {
text: "Calendar",
details: "Uses calendar information",
checked: false
}, {
text: "Contact",
details: "Uses contact information",
checked: false
}];
$scope.selection = [];
$scope.selection1 = [];
// toggle selection for a given employee by name
$scope.toggleSelection = function toggleSelection(item) {
var idx = $scope.selection.indexOf(item);
var jsonO = angular.copy(item);
jsonO.timestamp = Date.now();
DataService.setTrackedData(jsonO);
$scope.selection1 = DataService.getTrackedData();
// is currently selected
if (idx > -1) {
$scope.selection.splice(idx, 1);
}
// is newly selected
else {
DataService.setSelectedData(item);
$scope.selection = DataService.getSelectedData();
/* $scope.selection.push(item);*/
}
};
});
Error is like this ->
ReferenceError: DataService is not defined
at new <anonymous> (http://localhost:8100/js/app.js:82:5)
at e (http://code.ionicframework.com/1.0.0/js/ionic.bundle.min.js:67:315)
at Object.instantiate (http://code.ionicframework.com/1.0.0/js/ionic.bundle.min.js:67:432)
at Object.<anonymous> (http://code.ionicframework.com/1.0.0/js/ionic.bundle.min.js:68:184)
at Object.e [as invoke] (http://code.ionicframework.com/1.0.0/js/ionic.bundle.min.js:67:315)
at Object.$get (http://code.ionicframework.com/1.0.0/js/ionic.bundle.min.js:65:268)
at Object.e [as invoke] (http://code.ionicframework.com/1.0.0/js/ionic.bundle.min.js:67:315)
at http://code.ionicframework.com/1.0.0/js/ionic.bundle.min.js:69:110
at d (http://code.ionicframework.com/1.0.0/js/ionic.bundle.min.js:67:13)
at e (http://code.ionicframework.com/1.0.0/js/ionic.bundle.min.js:67:283) <div ui-view="">
Thanks in advance.