0

I have used a datepicker directive in my code. My idea is, when a date is selected from the datepicker, the selected date must be printed on the screen.

Any suggested code regarding this issue? This was the code :

  <script language="javascript">
     angular
        .module('myapp', ['ngMaterial','ngMessages'])
        .controller('dateController', dateController);

     function dateController ($scope) {
        $scope.myDate = new Date();

        }

      </script>
      </head>

        <body ng-app="myapp"> 
  <div class="datepickerdemo" ng-controller="dateController as ctrl" layout="column" ng-cloak>
     <md-content>
        <h4>Standard Date Picker</h4>
        <md-datepicker 
           ng-model="myDate" 
           md-placeholder="Enter Date" ></md-datepicker>
           </md-content>

           </div>
           </body>
           </html>

And my doubt is how can get selected date when it is changed

2
  • 1
    please show us what you have done so far Commented Jan 19, 2016 at 5:41
  • Welcome to stack overflow. Can you please tell what have you tried till now and what is the issue you are stuck in? A working js fiddle would really help. Commented Jan 19, 2016 at 5:46

1 Answer 1

1

The local scope property & might be the right thing for that. You can define a callback function using the chosen date as a parameter.

In your directive JS:

return {
    ...
    scope: {
        onSelect: '&'
    }
    ...
}

When using your directive you can define an on-select parameter giving a callback function, that you can use e.g. inside your link function.

Using local scope properties is the way to go in AngularJS, when exchanging data between a directive and the outer "world".

More info at AngularJS docs

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.