Injecting a view into another view

poq2011's Avatar

poq2011

26 Apr, 2013 04:44 PM

Classic question, but even after reading the post in the forum, i can't make it work

I want to inject a instance of View 1 into View2.

In my context, I have

injector.mapValue(View1, view1Instance); viewMap.mapType(View2);

In View2, I have

[Inject] view1Instance : View1;

But view1Instance is always null when I instance View2

What I am missing ?

  1. Support Staff 1 Posted by Ondina D.F. on 26 Apr, 2013 05:11 PM

    Ondina D.F.'s Avatar

    Hi poq,

    You can’t inject into views in the latest versions of rl1. You’d need the mediator of View2 to provide the view with an injector like this:

    [Inject] 
    public var injector:IInjector;
    
    [Inject] 
    public var view:View2;
    
    override public function onRegister():void
    {
        injector.injectInto(view);
    }
    

    You map View1 like this:

    injector.mapValue(View1, new View1());

    and in your View2 you inject it like this:

    [Inject] public var view1:View1;

    Hope that helps :)
    Ondina

  2. 2 Posted by poq2011 on 26 Apr, 2013 05:28 PM

    poq2011's Avatar

    Hi Ondina,

    Great, it works!

    For those interrested, I had to use a [PostConstruct] init function in order to get it worked!

        [PostConstruct]
        public function init():void
        {
            trace(view2, 'to check if it is null'); // And it is not!!
        }
    
  3. Support Staff 3 Posted by Ondina D.F. on 26 Apr, 2013 05:34 PM

    Ondina D.F.'s Avatar

    Cool :)
    I'm going to close this.

  4. Ondina D.F. closed this discussion on 26 Apr, 2013 05:34 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac