Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ac-change runs before model is updated? #46

Open
ghost opened this issue Aug 28, 2015 · 1 comment
Open

ac-change runs before model is updated? #46

ghost opened this issue Aug 28, 2015 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 28, 2015

ac-change seems to run before the model is updated.

Angular's ng-change runs after model update..

Doesn't it make sense to do the same as angular?

@ghost
Copy link
Author

ghost commented Aug 28, 2015

I've created a workaround for the problem. Don't know it is the most efficient but is works for what I need without changing too much =)

Add

"afterModelChange" :"&", 

to the scope of the directive.
Add a watch to the confirmedItem

$scope.$watch("confirmedItem.text", function () { 
                if ($scope.confirmedItem != null && $scope.confirmedItem.text != "" && typeof $scope.afterModelChange === 'function') {
                    $scope.afterModelChange();
                }
            }, true);

It makes this possible:

<ac-select after-model-change="DoYourThing()" ac-model="myModel" ac-options="item.ItemProperty for item in getItems()"></ac-select>

In the controller DoYourThing is called after model update, so $scope.myModel can be used in it.
$scope.myModel will contain the last selected item instead of the old one (which is the case with ac-change)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants