javascript - How can a controller know that the scope is valid -


I'm a bit confused by the verification in angular. All assumptions seem to be bound to the form. But what can you do in those cases where the controller should know whether the model is valid or not?

I knocked and gave examples:

html

   & Lt; Span ng-show = "travelForm.DepartureAirport. $ Error.required" & gt; Invalid & lt; / Span & gt; & Lt; / Ng form & gt; & Lt; A class = "removeJourney" ng-click = "removeInboundJourney ($ index)" href = "javascript: void (0)" & gt; Remove & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; Span ng-show = "valid ()" & gt; These are all valid & lt; / Span & gt; & Lt; Span ng-click = "Addinbound Journey" title = "Add a tour" & gt; + & Lt; / Span & gt; & Lt; / Div & gt; & Lt; / Div & gt;  

javascript

  var stpApp = angular.module ('stpApp', []); StpApp.controller ('multiStopController', function ($ scope, $ compilation, $ http) {$ scope.showAddButton = true $ scope.dataLoaded = false; $ scope.inboundJourney = [{'DepartureAirport': '', 'DestinationAirport' '', 'DepartureTate': '', 'DepartureTime': '9', 'Class': 'All'} {'DepartureAirport': 'Test1', 'DestinationAirport': '', 'DepartureDate': '', 'DepartureTime': '9', 'Class': 'All'}] $ scope.valid = function () {// How do I test validity here; return true;} $ scope.addInboundJourney = function ()? { $ Scope.inboundJourney.push ({'DepartureAirport': '', 'DestinationAirport': '', 'DepartureDate': '', 'DepartureTime': 9, 'Class': ''});} $ scope.removeInboundJourney = Function (index) {$ scope.inboundJourney.splice (index, 1);}});  

So I want my valid () function to be true or false depending on whether the data is valid in the model or No . I've tried travelForm. $ Valid , $ scope.journeyForm. $ Valid and $ scope.journeyFormDepartureAirport $ Valid . None of these work.

I can not figure out how to check $ valid from inside my controller. especially I have variable number forms

Should the controller also have knowledge of forms? Is it in view?

I think the issue is that the belief is within seeing everyone. I guess there is no concept of invalid model in angle. It's just data but, well, this is a problem for me. I want to know that the model meets all of my criteria ( Is added to the view, like ng-required ) before I do some work in the controller. Comment on using

$ valid

  & lt; Form name = "myform" & gt; & Lt; Input type = "text" name = "input1" ng-required = "true" /> ....  

JS

  $ scope.valid = function () {return $ scope.myform. $ Valid; / * How to return $ $ valid for 'myform' form * /}  

Comments