samedi 9 mai 2015

how to pass only two properties to a $scope variable

ANGULARJS Question:

I got an array of objects and I need to pass it to my $scope variable. THe property that's creating a problem for me in special is the 'user:' property. since it holds elements like the name and email it affects the way the filter i set in the HTML is filtering the objects I want to display. The object is a list of notes and I want to be able to filter them by content in the note( title and body text)

I have tried to delete the property user from the object with the code below, but that does not work. $scope.notes still loads that attribute.

Ideally I should be able to pass to $scope.notes only the title and body attributes. Any ideas of how to do that efficiently?

 var notes = notesService.notesObjectInService;
    for (var i = 0;  i < notes.length; i++) {
        delete notes[i].user;
    };

    $scope.notes = notes;

This is the json object passed to notes in the first line.

[{"id":184,
"title":"Mari",
"body":"Mae",
"created_at":"2015-05-09T03:23:04.250Z",
"updated_at":"2015-05-09T03:23:04.250Z",
"user_id":1,
"user":{"id":1,
"email":"vini@vini.com",
"created_at":"2015-04-24T22:49:21.797Z",
"updated_at":"2015-05-09T03:04:27.739Z",
"username":"vinivini"}}]

Aucun commentaire:

Enregistrer un commentaire