D
D
Die_Gelassenheit2014-12-11 17:00:01
Angular
Die_Gelassenheit, 2014-12-11 17:00:01

What is the best way to implement auto hints in AngularJS?

Do I understand correctly that the best way to work with the behavior of a particular element in AngularJS is to use directives?
For example, I want to make a form with auto-prompts, which will be formed from preset values ​​+ those that will already be entered into the form.
Is it worth using a directive (to change the html of an element and draw a drop-down list of hints) and a service (in which the actual values ​​of the inputs will be stored) for this? How generally correct to use directives for such dynamic things?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita Gushchin, 2014-12-11
@iNikNik

The directive in this case will make the code reusable - you can make a second form and use the same code on it. In other words, the use of the directive is fully justified.
What about:
I don't know how beautiful it will be. For example, you can make an isolated scope for the directive and pass an array there with

auto-prompts, which will be formed from predefined values ​​+ those that will already be entered into the form

A
Alexey Ivanov, 2014-12-12
@AlexeyIvanov

I think it's best to use two directives here:
1. One for the form, for example HintForm. In it, declare a directive controller in which you will store the actual values ​​of the inputs.
2. For the inputs themselves, for example Hint. When declaring the directive, specify require: ^HintForm, then the controller from HintForm will be available to you in the link function. When you change the value in the input, you will write it (the value) to the HintForm controller. Since the HintForm controller is rummaged between all Hints, any Hint directive will know the actual input values ​​in the entire form through it.
This is similar to how the form directive interacts with nested ng-model directives.
Example: http://plnkr.co/edit/TQQWJflPSQx5jDh097bM

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question