JavaScript Angular directive data binding not working properly angular directive data binding,angular directive data,angular directive data

To fix the problem

You'll need to listen to changes to the input field and update scope.time.

First change I did was to include Angular after jQuery, that way the element parameter will be a jQuery object.

Then listen to the change event and update scope.time. Wrap the call in scope.$apply to tell Angular that something has changed.

element.on('change', function () {
    scope.$apply(function () {
        scope.time = element.datepicker('getDate');
    });
});

Plunker

Alternative approach

Personally when writing directives that are applied on input elements I want to allow the user to use ngModel directive to keep the data in sync, since that is a known convention. By using ngModel you could also (optionally) use it's controller to add custom validation or other logic, e.g. parsers/formatters (not needed in this case).

By using the $parse service we can read/write data back to the ngModel field.

I also changed so that datetime options can be passed if needed.

Lastly I moved the first datetime() call to the compile function since that's the place where DOM manipulation should be made.

.directive("datetime", ['$parse', function($parse) {
  return {
      require: '?ngModel',
      restrict: 'A',
      compile: function (element, attrs) {
        var options = $parse(attrs.datetime)() || {};
        console.log('Passed options:', options);

        element.datepicker(options);

        // Return the link function
        return function (scope, element, attrs, ngModel) {
          var getter, setter;

          // If the ngModel directive is used, then set the initial value and keep it in sync
          if (ngModel) {
            getter = $parse(attrs.ngModel);
            setter = getter.assign;

            console.log('ngModel directive used, setting initial value')
            element.datepicker("setDate", getter(scope));

            scope.$watch(attrs.ngModel, function(val, prev) {
              console.log('ngModel changed from', prev, 'to', val);
            });

            element.on('change', function () {
              console.log('change');
              var newValue = element.datepicker('getDate');
              scope.$apply(function () {
                setter(scope, newValue);
              });
            });
          }
        };
      }
  };
}])

And the directive is used like this:

<input type="text" datetime="{showButtonPanel: true}" ng-model="parentTime" />

Plunker

Answer:1

This is the javascript for ajax html popup <script type="text/javascript"> $(document).ready(function() { $('.ajax-popup-link').magnificPopup({ type: 'ajax', overflowY: '...

This is the javascript for ajax html popup <script type="text/javascript"> $(document).ready(function() { $('.ajax-popup-link').magnificPopup({ type: 'ajax', overflowY: '...

  1. make function button excel
  2. make button function
  3. make button function as lever
  4. make button function javascript
  5. make button function in java
  6. how to make function button work
  7. how to make button function in android studio

I try to remove the duplicate value before storing it into a store. I want to store the same value in the store 1 time only. But it seems the following Ext.Array.unique line does not working. Could ...

I try to remove the duplicate value before storing it into a store. I want to store the same value in the store 1 time only. But it seems the following Ext.Array.unique line does not working. Could ...

  1. extjs remove duplicate records from store
  2. extjs remove duplicates from store
  3. extjs remove duplicates from array
  4. extjs remove duplicates
  5. extjs combobox remove duplicate

So I have a header.. and an image. On tablet I want to be able to pinch and zoom into the image but i'm struggling. I've looked at other similar questions. But as I'm still learning, i'm not fully ...

So I have a header.. and an image. On tablet I want to be able to pinch and zoom into the image but i'm struggling. I've looked at other similar questions. But as I'm still learning, i'm not fully ...

  1. pinch zoom using hammer.js
  2. hammer.js pinch zoom
  3. pinch zoom hammerjs

Let's say I have something like this: <div ng-app="myApp"> <div ng-controller="myCtrl"> {{foo}} <button ng-click="bindToMe" /> </div> <div ng-...

Let's say I have something like this: <div ng-app="myApp"> <div ng-controller="myCtrl"> {{foo}} <button ng-click="bindToMe" /> </div> <div ng-...

  1. programmatically bind combobox c#
  2. programmatically bind datagridview c#
  3. programmatically bind visibility
  4. wpf programmatically bind property
  5. wpf programmatically bind dependency property
  6. objectdatasource programmatically bind
  7. wpf programmatically bind
  8. bind gridview column programmatically c#
  9. vue bind programmatically
  10. angular bind programmatically
  11. knockout data-bind programmatically
  12. wpf datagrid bind programmatically
  13. nsarraycontroller bind programmatically
  14. v-bind programmatically
  15. c# bind programmatically
  16. cocoa bind programmatically