2

controldirective.js

  function validVehicleyear($scope, $http) {
        return {
            restrict: 'C',
            scope: {
                ngModel: '=',                
            },
            link: function (scope, element, attrs, ngModel) {
                element.bind('change', function () {
                    console.log('here in validVehicleyear');
                    $http.get('api.php/'+scope.ngModel)
                            .then(function (response) {
                                $scope.answers.VehicleMake = response.data;
                            });
                });
            }
        }
    }

plnkr.co/edit/BFGXr7LNAe0KvQipj9JJ?p=preview

I wrote a directive validVehicleyear on class at Vehicle year question, this i want to call on change of year and set new options for Vehicle make, but it not working.

Class="form-control **valid-vehicleyear** ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched"

1 Answer 1

1

You forgot to declare your directive function

.directive('validVehicleyear', validVehicleyear)

http://plnkr.co/edit/9bGXO96s0BJVik7VecFU?p=preview

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

7 Comments

thanks . I updated plunker. you did changes in changed <select valid-vehicleyear in controlDirective.js, I can not line like that, So I created a class on which i want to create a directive.
restrict: 'C', works to cretae directive but its not working
@pandudas yes, I mistook C for comment directive. But regardless the plunker works. An alert popsup when you change the year. EDIT: oh I see what you mean
Yes I missed to add above line in plunker. At the final I want to make it working with restrict: 'C', why it is directive not working on class. What I am missing.
Right, I couldn't figure why it doesn't work with class. Maybe a conflicting class name css vs directive? I never use directive as css classes. I find it confusing and very bad practice. You should probably refactor your code.
|

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.