Type notes into field. "Enter" or "Add" - to Add note to Notes.
Five notes (max) will be written to notes (newest first).
If there are more notes, the oldest note will be archived:
Notes: {{getNotes()}}
Archive: {{getArchive()}}
We have two services, Archiv:
var Archive = function() {
this.store = [];
};
...
and Notes:
var Notes = function (archive) {
this.archive = archive;
this.store = [];
};
...
To use these services in our controller, we register them:
angular.module('notesApp', [])
.value('archive', new Archive()) //register 'archive' as new Archive()
.service('notes', Notes)//register 'notes' as constructor-function for Notes
.controller('NotesCtrl', function ($scope, notes, archive) { ... }
//Using registered variables 'notes' and 'archive'
-
.value - is the simplest registering. We can register only instances here.
-
.service - is second simplest registering. We can register here constructor functions
So it is possible to register objects with dependencies to other objects.