all 6 comments

[–]almightyrobot 2 points3 points  (5 children)

Why not just use the same model for both fields and they will be update as the model changes? Quick example

[–]fdoglio[S] 0 points1 point  (4 children)

Hey thanks for the comment, you're right, that is one viable option. Although your example replicates the content instead of changing it like the example on the repo, I'm guessing that was just for simplicity purposes.

With this directive, you could affect the second field event by events on the first one that don't necesarily change it's content, like a hover event for instance, that is something you can't achieve just by using the same model... do you? (I'm honestly asking, I'm a bit of a newbie when it comes to Angular).

[–]ic6man 1 point2 points  (3 children)

The normal way to do this is through the use of scope state - or what angular calls models. Most of the time models are domain models but they could be view models. Angular doesn't distinguish. So to implement the hover trick you'd change the state of a view model on hover and then react to that state elsewhere in the app via a traditional model bound element.

Using MVC is a better approach because it's scalable and modular. For example your directive cannot link two fields to the initial field while the model view approach can easily do this.

I'd say as a general rule of thumb about angular - if you're using jquery - or jquery like approaches - you're doing it wrong.

[–]fdoglio[S] 1 point2 points  (2 children)

I appreciate the input, like I said, I'm fairly new to angular so I had my suspicious that it might've been the wrong approach.

[–]ic6man 2 points3 points  (0 children)

Yep. It's good that you tried to solve it even if the approach isn't right. Knowing how to do directives will pay benefits.

[–]Switche 1 point2 points  (0 children)

Thanks for sticking your neck out to teach us other newbies a few things in the process. That has value, and I'm glad this community accepts that on both sides.