i trying resolve list of customers prior rendering page.
here state provider reference, have resolve methods.
angular.module('app') .config(($stateprovider) => { $stateprovider .state('customers', { url: '/customers', template: '<customers></customers>', resolve: { test: function () { return 'nihao'; }, }, }); });
followed component, should have called #test resolve. should do, print word 'nihao' console.
(function mycustomersconfig() { class mycustomerscomponent { constructor(test) { this.test = test; console.log(this.test); } angular.module('app').component('mycustomers', { templateurl: 'app/customers/customers.html', controller: mycustomerscomponent, }); }());
however, keep getting error:
angular.js:13708 error: [$injector:unpr] unknown provider: testprovider <- test http://errors.angularjs.org/1.5.7/$injector/unpr?p0=testprovider%20%3c-%20test @ angular.js:68 @ angular.js:4502 @ object.getservice [as get] (angular.js:4655) @ angular.js:4507 @ getservice (angular.js:4655) @ injectionargs (angular.js:4679) @ object.invoke (angular.js:4701) @ $controllerinit (angular.js:10234) @ nodelinkfn (angular.js:9147) @ angular.js:9553
i can see it's running resolve functions, works, won't inject methods! ideas?
your code missing attribute , binding in order resolve work.
angular.module('app') ... template: '<customers test="$resolve.test"></customers>', resolve: { test: function () { return {value: 'nihao'}; } }, ... }); (function mycustomersconfig() { function mycustomerscomponent { // can use test right away, , view $ctrl.test console.log(this.test); } angular.module('app') .component('mycustomers', { templateurl: 'app/customers/customers.html', controller: mycustomerscomponent, bindings: { test: "<", } }); }());
Comments
Post a Comment