0

I am writing an app with Ionic 1.3.5 and AngularJS 1.5.3.

I have nested components and a component factory that decides which child component to render.

One child type has an onClick call back that I am trying to propagate to the parent. I keep getting this error: Cannot use 'in' operator to search for '$ctrl' in Today

Here is my factory:

<clickable-list
    ng-if="$ctrl.type === 'clickableList'"
    on-click="$ctrl.onClick(value)"
    answer="$ctrl.answer">
</clickable-list>

<plain-text-answer
    ng-if="$ctrl.type === 'plainText'"
    answer="$ctrl.answer">
</plain-text-answer>

I was able to fix my Plunker so it runs and reproduces the error: http://plnkr.co/edit/ESTMPRRpdRuks6AJdRxv

1 Answer 1

1

First, your plunker does not work cause you must have spaces:

template: ['<component', 'value="1">', '</component>'] 

result in html <componentvalue="1"></component>

Second, your problem is how you chain calls passing value. To make it work without additional methods you need:

one component

<c1 ng-click="$ctrl.onClick({value: value})">

two components

<c1 on-click="$ctrl.onClick({value: value})">
<c2 ng-click="$ctrl.onClick({value: {value: value}})">

...

Since this is a bit retarded, it is better to create intermidiate methods:

c1: (onClick: '&')
vm.doClick = (value) => {
  vm.onClick({value: value});
}

then you have fancy html for c1: <c2 ng-click="$ctrl.doClick({value: value})">

http://plnkr.co/edit/27cCqsnACtdIz00PfI3E?p=preview correct plunk

Sign up to request clarification or add additional context in comments.

1 Comment

This worked but in my real code base I need to go up a few more levels... I don't understand why it's necessary to wrap it several times or use intermediate methods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.