Hi,
I'm working with angularjs for some weeks now, and I don't get what the 
angularjs designers thought when designing the $viewValue and $modelValue 
functionality from the ngModelController 
<https://docs.angularjs.org/api/ng/type/ngModel.NgModelController>.

*my angular application:*
*index.html*
<!DOCTYPE html>
<html>

  <head>
    <script data-require="angular.js@*" data-semver="1.3.0-beta.5" src=
"https://code.angularjs.org/1.3.0-beta.18/angular.js";></script>
    <script src="script.js"></script>
  </head>

  <body ng-app="PlunkerApp" ng-controller="mainController">
    <listfield ng-model="termList"></listfield>
  </body>

</html>

*script.js*
var plunkerModule = angular.module('PlunkerApp', []);

plunkerModule.directive('listfield', function() {
  'use strict';
  var link = function(scope, element, attrs, ngModelController) {
    console.log('listfield.link():', scope);
    ngModelController.$parsers.push(function(value) {
      console.log('listfield.model.parser:', value);
      return value ? value.join(', ') : undefined;
      
    });
    ngModelController.$formatters.push(function(value) {
      console.log('listfield.model.formatter:', value);
      return value ? value.split(/,\s*/) : undefined;
    });
  }
  return {
    restrict: 'E',
    link: link,
    require: 'ngModel',
    scope: {
      ngModel: '='
    },
    template: '<input type="text" ng-model="ngModel">'
  };
});

plunkerModule.controller('mainController', function($scope) {
  $scope.termList = "";
  $scope.$watchCollection('termList', function(newValue, oldValue) {
    console.log('mainController.watch.list:', newValue);
  });
});

*plunker link:*
http://plnkr.co/edit/T5a8zEQuRyYWnpsZZV9W?p=preview

So in this application the value from the directives input element is 
written into the global scope which works fine. My problem is, I'm not 
interested in the "raw" string value, i want the array that is generated by 
the formatter (in this case) but the input element should still show the 
string value. 

How can I do that??


Looking forward to your answers.

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to