1

I'm creating a datepicker directive, part of its markup is:

<select class="form-control" ng-model="day" ng-options="day.nr for day in allDays">

I'm trying to define allDays in the scope attribute like this:

ehrApp.directive('datePicker', function() {
  return {
    scope: {
      allDays: [
      {'nr': 1},
      {'nr': 2},
      {'nr': 3},
      (...)
      {'nr': 31}
      ]
    },

But it doesn't work, it fails with "TypeError: undefined is not a function".

Any ideas how to achieve this?

1 Answer 1

1

You are defining the value inside the scope attribute of the directive configuration, which is where you'd define the isolate scopes the directive uses. Instead of doing it there, do it either in your link function or in your controller function:

return {
   link : function (scope, element, attrs) {
       scope.allDays = [{nr : 1}];
   }
}

or

return {
   controller : function ($scope, $element) {
       $scope.allDays = [{nr : 1}];
   }
}
Sign up to request clarification or add additional context in comments.

Comments

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.