I have developed a straightforward service as shown below:
var app = angular.module('myApp', ['ngRoute']);
app.service('UserService', function() {
this.user = {firstName:"",middleName:"",lastName:"",email:"",dob:""};
this.addUser = function (user) {
users.push(user);
}
this.displayUser = function (user) {
this.user = user;
}
});
Below is the controller where I intend to make use of the service:
app.controller('DisplayUserController', ['$scope','UserService',
function($scope, UserService) {
$scope.user = UserService.user;
}]);
This snippet showcases the HTML section where I am passing the user object to user directive:
<div ng-controller="DisplayUserController">
<div>{{user.firstName}}</div>
<div>{{user.middleName}}</div>
<div>{{user.lastName}}</div>
</div>
Any idea why I keep encountering the "Unknown provider: userProvider <- user" error? Assistance would be greatly appreciated.