I am in the process of migrating my AngularJS application to Angular 2. In my AngularJS controller, I had a JSON array that I was iterating through to display data in an accordion list. Now, I need to implement the same functionality in my Angular 2 component.
This is the code snippet from my AngularJS application:
myApp.factory('Plan', function() {
var days = [
{ "id": 0,
"name": 'Your Training Plan for Today',
"exercises":[
{"id":1,"name":'Best Stretch', "watchedToday": 'false', "type":"body"},
{"id":8,"name":'Colors', "watchedToday": 'false', "type":"memory"},
// More exercise items...
]
}
];
return {
all: function() {
return days;
},
get: function(dayId) {
return days[dayId];
}
}
});
//In my controller
$scope.days=Plan.all();
angular.forEach($scope.days, function(value1, key){
angular.forEach(value1.exercises, function(value2, key){
if(value2.id==game_type && $scope.today === current_date_memory){
value2.watchedToday=true;
}
});
});
I am looking for guidance on how to translate this logic into Angular 2 code.
In my Angular 2 component, I have started with:
export class ContactPage {
days = [
{ "id": 0,
"name": 'Your Training Plan for Today',
"exercises":[
{"id":1,"name":'Best Stretch', "watchedToday": 'false', "type":"body"},
{"id":8,"name":'Colors', "watchedToday": 'false', "type":"memory"},
// More exercise items...
]
}
];
constructor(public navCtrl: NavController) {
}
}