After much hassle I've managed to get a working example for you using the &attr
isolated scope syntax which provides a way to execute an expression in the context of the parent scope, in your example all the way up to the showQuestion()
function on your QuestionsCtrl controller.
Understanding ng-show in AngularJS directives
-
01-09-2022 - |
Question
Given the following code:
http://jsbin.com/uYETOSUM/2/edit?html,js,output
I want to only show the first dropdown first (parent question in JSON). After user have selected an option I want to show one of the two other dropdowns (children in additionalQuestion object in JSON). Which dropdown to show is given in the JSON used to create the form input fields.
To do this I've experimented with ng-show
, but I don't seem to find the proper place to put the custom ng-show
code. I want ng-show
to be like this in the template:
ng-show"showQuestion()"
where showQuestion()
iterates through all questions and matches the PreviousQuestionConstraint
to see which of the other questions to show based on the value of the selected option in the first question.
- Should it be in the Controller?
- Should it be in the Directive?
- Should it be in the linker function in the Directive?
All attempts so far have resulted in nothing being shown.
Solution