i trying inject service controller using resolve property of $routeprovider getting error when run it. suggestion great. in advance.
error: [$injector:unpr] unknown provider: messageprovider <- message
gituserservice.js
module.exports = function (app) { app.factory('gituser', ['$http', function ($http) { return { getgituser: function (username) { return $http.get('https://api.github.com/users/' + username) .then(function success(response) { return response.data.login; }, function error(response) { return console.log("error"); }); } }; }]); };
route.js
module.exports = function (app) { require('../../services/gituserservice')(app); app.config(['$routeprovider', function ($routeprovider) { $routeprovider.when('/angularhome', { template: '<home></home>', resolve: { message: ['gituser', function (gituser) { return gituser.getgituser('test'); }] } }) }]); };
homecontroller.js
require('./home.scss'); module.exports = function (app) { app.component('home', { templateurl: 'content/app/components/home/home.html', controller: ['message', homecontroller] }); function homecontroller(message) { this.name = message; } };
index.js
module.exports = function (app) { require('./route')(app); require('./homecontroller')(app); };
updated code based on responses , fix.
homecontroller.js
require('./home.scss'); module.exports = function (app) { app.component('home', { templateurl: 'content/app/components/home/home.html', controller: homecontroller, bindings: { name: '<' } }); function homecontroller() { this.name = name; } };
route.js
module.exports = function (app) { require('../../services/gituserservice')(app); app.config(['$routeprovider', function ($routeprovider) { $routeprovider.when('/angularhome', { template: '<home name="$resolve.message"></home>', resolve: { message: ['gituser', function (gituser) { return gituser.getgituser('test'); }] } }) }]); };
Comments
Post a Comment