I have recently started working on implementing a notifications feature. The service will involve making a GET request to a specific URL which will then return an array of notifications.
Within the controller, I am in the process of setting up a variable that will hold a message string for each different notification type. Since I am still new to Angular, I just want to confirm if my syntax and logic are correct.
/* Model + Controller */
// Assume this code is wrapped in a controller function
$scope.notifications = notifications=[
{id:1, type: 6},
{id:2, type: 3},
{id:3, type:4}];
$scope.display_message = function(){
if ($scope.notifications.type == 1){
$scope.notification_message = "some text";
} else if ($scope.notifications.type == 2){
$scope.notification_message = "some text";
}
//... additional logic for brevity
return $scope.notification_message
}
/* View */
<li ng-repeat={{notification in notifications}}>
{{display_message()}}
</li>