i am using ui-router and there i am resolving some data i want to inject the resolve to my custom directive ,below is code how i am doing
module portal {
$stateProvider.state('portal', {
url: '/demo',
template: tpl.html,
abstract: true,
resolve: {
demoResolve:function(){
return 'foo';//here i am returing a promise
}
});
}
module portal.directives{
export class demoDirevtive{
static $inject =['demoResolve'];
constructor(demoResolve){
console.log(demoResolve)
var directive: ng.IDirective = {};
directive.link = (scope, element, attrs, ctrl) => {
};
directive.restrict = "EAC";
return directive;
}
}
}
but i am getting error of unknown provider
The ui-router is effective for the larger application because it allows nested-views and multiple named-views, it helps to inherit pages from other sections. In the ngRoute have to change all the links manually that will be time-consuming for the larger applications, but smaller application nrRoute will perform faster.
A ui-sref is a directive, and behaves similar to an html href . Instead of referencing a url like an href , it references a state. The ui-sref directive automatically builds a href attribute for you ( <a href=...> </a> ) based on your state's url.
UI-Router is the defacto standard for routing in AngularJS. Influenced by the core angular router $route and the Ember Router, UI-Router has become the standard choice for routing non-trivial apps in AngularJS (1. x).
From reading their code it doesn't seem like it's possible, they have a local variable that they inject into the controller you define on the view, it's not accessible via $inject service as well.
Easiest solution would be to put it on the controller's scope, and then use it in the directive.
You can also create a real service, that will hold all the resolved objects in your application, i.e.:
resolve: {
demoResolve: ['myResolvingService', function(resolver) {
resolver.myValue = 'Foo';
return 'Foo';
}]
I know it's not what you were looking for, but it just doesn't look like it's supported.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With