Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

injecting ui-router resolve to directive

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

like image 791
Pranay Dutta Avatar asked Oct 14 '14 06:10

Pranay Dutta


People also ask

What is the difference between ngRoute and UI-router?

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.

What does UI sref do?

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.

What is UI in router?

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).


1 Answers

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.

like image 102
PiniH Avatar answered Oct 01 '22 15:10

PiniH