0

I know Angular pretty well, use it everyday, but apparently, I'm having one of those days..

I'm probably missing something hideously obvious, but why aren't I seeing testForm.testField.$invalid & testForm.testField.$dirty etc???

var myApp = angular.module('myApp',[]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
    <form name="testForm">
        <input type="text" name="testField" ng-model="testField" required="required" />
        {{testForm | json}}    
        {{testField}}
    </form>
</div>

2
  • I'm new in angular, but I see that testField is part of the angular model (there is a ng-model="testField"), but I cannot see testForm as part of it Commented Nov 19, 2014 at 14:11
  • 1
    @Pablo No worries, when you have a form in angular, the name of the form will be the variable in the scope, that refers to it. Alternatively you can do: ng-form="myVariableName". Commented Nov 19, 2014 at 14:53

1 Answer 1

2

If you look in the Angular source, the conversion to JSON says:

Properties with leading $ characters will be stripped since angular uses this notation internally.

Unfortunately the documentation for the json filter doesn't mention that.

See https://github.com/gaborcs/angular.js/blob/master/src/Angular.js lines 930-931.

Sign up to request clarification or add additional context in comments.

1 Comment

That's it! Thanks ! Was slightly less obvious than I thought it would be!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.