JavaScript ng-model breaks in transcluded input

I am writing a directive which is really simple: it should wrap an input element in a div. I use transclusion for this. The problem is that it breaks ng-model for some reason. Please see this plunker for the full code: http://plnkr.co/edit/tYTsVUbleZV1iG6eMgjo

What can I do to make ng-model behave as expected?

Directive code

Here's the code for the directive:

testapp.directive('wrapInput', [function () {
   return {
      replace: true,
      transclude: 'element',
      template: '<div class="input-wrapper" ng-transclude></div>'
   };
}]);
Answer:1

If you change your markup to look like this

<div  wrap-input>
  <input type="text" ng-model="anObject.anotherValue"/>
</div>

And then you can also use

transclude: true // instead of transclude: 'element'

It works just fine. I can't speak as to why, but I've seen this issue before when using both transclude: 'element' and replace: true. I'll have to dive into the source later to see what's going on. Reagrdless, the resulting markup with this workaround should be the same.

Answer:2

I figured since ng-repeat can do it, it must be possible:

http://plnkr.co/edit/stf02iPNvNnlsx1dsFZx?p=preview

app.directive( 'wrapThisThing', [ '$compile', function( $compile ) {
  return {
    restrict: 'A',
    transclude: 'element',
    link: function( scope, element, attrs, ctrl, transclude ) {

      // Compile a new DOM context and bind it to our scope.
      var template = angular.element( '<div class="wrap">' );
      var context = $compile( template )( scope );

      transclude( function( clone, theScope ) {
        // To make this work, we need to remove our directive attribute from
        // the clone before compiling it back to its original scope. If we
        // don't do this, the compiler will re-evaluate our directive, creating
        // an infinite loop.

        // We can use the $attr property to figure out what attribute variation
        // was used (ie. data-wrap-this-thing, x-wrap-this-thing, wrap:this:thing,
        // etc.).
        // See more about attribute normalization:
        // http://www.bennadel.com/blog/2648-inspecting-attribute-normalization-within-directives-in-angularjs.htm

        clone.removeAttr( attrs.$attr.wrapThisThing );

        // Compile the transcluded element and bind it to its own scope. Then
        // append it to our new context.
        context.append( $compile( clone )( theScope ) );
      });
      element.replaceWith( context );
    }
  };
}]);
Answer:3

Since Node.js is (seemingly) single threaded (partially for network reasons), does it mean it can only use one CPU core at any time? Can I even get a single core server these days?

Since Node.js is (seemingly) single threaded (partially for network reasons), does it mean it can only use one CPU core at any time? Can I even get a single core server these days?

There is probably an easy solution for this: I have some data in a controller, depending if item is selected it should display some html and if it's not selected it should display some other html. ...

There is probably an easy solution for this: I have some data in a controller, depending if item is selected it should display some html and if it's not selected it should display some other html. ...

  1. angularjs ng-repeat data binding
  2. angularjs ng-repeat $data

Do you know why this function deleteInputOnClick(input){ champ = document.getElementById(input); if(champ.value =='E-mail'){ champ.value = ""; } } works but this way function ...

Do you know why this function deleteInputOnClick(input){ champ = document.getElementById(input); if(champ.value =='E-mail'){ champ.value = ""; } } works but this way function ...

  1. getelementbyid cannot find element
  2. getelementbyid canvas
  3. getelementbyid cannot set property of null
  4. getelementbyid canvas null
  5. getelementbyid canvas getcontext 2d
  6. getelementbyid caniuse
  7. cannot getelementbyid
  8. canvas getelementbyid returns null
  9. document.getelementbyid can't find element
  10. document.getelementbyid('canvas').getcontext('2d')
  11. document.getelementbyid('canvas')
  12. document.getelementbyid cannot find element
  13. document.getelementbyid canvas is null
  14. typescript getelementbyid canvas
  15. javascript getelementbyid cannot find element
  16. document.getelementbyid cannot read property
  17. javascript getelementbyid canvas
  18. ctx u003d document.getelementbyid('canvas').getcontext('2d')
  19. getelementbyid cannot get element
  20. getelementbyid can't find element

I have a simple iojs http server which communicates with another http backend on my development machine. Now my ip has changed and the backend request won't work due to a wrong ip. I have (or at least ...

I have a simple iojs http server which communicates with another http backend on my development machine. Now my ip has changed and the backend request won't work due to a wrong ip. I have (or at least ...