2016-05-11 7 views
2

Ich bin in der Lage eine eigenständige Zeichenfolge in diesem Beispiel zu binden: http://plnkr.co/edit/GKZHSDe5J0eCzqlgaf4g?p=previewBinding Array von Richtlinie zu modellieren

jedoch, wenn die gleichen Versuch, aber mit einer Reihe von Strings, das Modell nicht mehr Updates: http://plnkr.co/edit/Fz9GFxWeZxRpsiqXgra4?p=preview

Dies ist der Anweisungscode:

app.directive('psDIR', [ 
    function() { 
     return { 
      template: "<div ng-init=\"models=['yp', 'hi']\" style='padding: 5px; border: 1px solid red; margin-bottom: 10px;'><p>This is a direcive:</p> <textarea ng-repeat=\"md in models\" rows='5' cols='50' ng-model='md'></textarea></div>", 
      restrict: 'AEC', 
      scope: {models:'=model'}, 
      link: function (scope, elm, attrs, ctrl) { 
       scope.$watchCollection('scope.models', function(){ 
        console.log(scope.models); 
       }); 
      } 
     } 
    } 
]); 

Was mache ich falsch, dass das Modell nicht mehr dem Array entspricht?

Antwort

0
app.directive('psDIR', [ 
    function() { 
     return { 
      template: "<div ng-init=\"models=['']\"><textarea ng-repeat=\"md in models track by $index\" ng-model='models[$index]'></textarea></div> {{validation}}", 
      restrict: 'AEC', 
      scope: {validation: '@', models:'=model'}, 
      link: function (scope) { 
       scope.$watchCollection('models', function(){ 
       console.log(scope.models); 
       }); 
      } 
     } 
    } 
]);