Unable to get ng-message to disappear when form is valid or reference form in controller Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!An invalid form control with name='' is not focusableAngularJs - How do I get my current form in my controller?Change classes and display message when form is submitted with AngularAngularjs form validation on Form SubmissionAngularJS custom form controls validationAngular w/ Typescript Validation messages not showing / hiding for a HTML form injected into the pageAngular 2 referring to controls for validation messagesHow to get AngularJS Validation working with ng-showForm Validation in Bootstrap Tabs (AngularJS)Unable to control html elements using form state

Delete nth line from bottom

Most bit efficient text communication method?

How do pianists reach extremely loud dynamics?

8 Prisoners wearing hats

What does the "x" in "x86" represent?

Can a new player join a group only when a new campaign starts?

Chinese Seal on silk painting - what does it mean?

How could we fake a moon landing now?

old style "caution" boxes

If a VARCHAR(MAX) column is included in an index, is the entire value always stored in the index page(s)?

How to convince students of the implication truth values?

Is "Reachable Object" really an NP-complete problem?

What are the out-of-universe reasons for the references to Toby Maguire-era Spider-Man in ITSV

また usage in a dictionary

Do I really need recursive chmod to restrict access to a folder?

What is the meaning of the simile “quick as silk”?

Circuit to "zoom in" on mV fluctuations of a DC signal?

Do jazz musicians improvise on the parent scale in addition to the chord-scales?

Is CEO the profession with the most psychopaths?

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

How to tell that you are a giant?

Is it common practice to audition new musicians one-on-one before rehearsing with the entire band?

Is there a kind of relay only consumes power when switching?

How do I find out the mythology and history of my Fortress?



Unable to get ng-message to disappear when form is valid or reference form in controller



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!An invalid form control with name='' is not focusableAngularJs - How do I get my current form in my controller?Change classes and display message when form is submitted with AngularAngularjs form validation on Form SubmissionAngularJS custom form controls validationAngular w/ Typescript Validation messages not showing / hiding for a HTML form injected into the pageAngular 2 referring to controls for validation messagesHow to get AngularJS Validation working with ng-showForm Validation in Bootstrap Tabs (AngularJS)Unable to control html elements using form state



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I know this question has been asked many times but none of the answers/resources have been able to help me.



I am trying to make a simple form in angular that will take a number and display a message if it is negative:



<div layout-padding ng-controller="BaseController as vm">
<form name="vm.mechanicalForm">
<input type="number" min="0" name="test" ng-model="vm.building.numberOfChillers" required />
<div ng-messages="vm.mechanicalForm.number.$error">
<div ng-message="min">
Test worked
</div>
</div>
<input type="button" ng-click="vm.save()" value="Save" />
</form>




Additionally, when I save the form, I want the controller to log one message if the form is valid, and another if it is not valid:



var app = angular.module('plunker', ['ngMessages']);
export class BaseController
public mechanicalForm;
public building;
constructor()
this.mechanicalForm = ;
this.building =
'numberOfChillers': 0
;


public save()
if (this.mechanicalForm.$valid)
console.log("This worked");

else
console.log("This did not work");



app.controller('BaseController', BaseController);


But it seems like my controller is not able to see the form at all. According to everything I have read I seem to be writing the code correctly. My two questions are:



1: Why will the ng-message not disappear when my input is valid?



2: Why is my controller not able to see my form object?



Here is a code pen Demonstrating my issue. I am using AngularJS 1.5.3



For reference, here are the resources I have referred to so far:



How to use ng-messages



AngularJS form and control state



Using 'controller as' syntax



common issues with ng-messages










share|improve this question
























  • Use basic debugging techniques to see the value of the form when the save button is clicked.

    – georgeawg
    Mar 8 at 19:38












  • I have already tried that approach only to see that the form value is either an empty object if I define it in the constructor of my controller or undefined if it is defined in the template.

    – Nikhil Badami
    Mar 8 at 22:09

















0















I know this question has been asked many times but none of the answers/resources have been able to help me.



I am trying to make a simple form in angular that will take a number and display a message if it is negative:



<div layout-padding ng-controller="BaseController as vm">
<form name="vm.mechanicalForm">
<input type="number" min="0" name="test" ng-model="vm.building.numberOfChillers" required />
<div ng-messages="vm.mechanicalForm.number.$error">
<div ng-message="min">
Test worked
</div>
</div>
<input type="button" ng-click="vm.save()" value="Save" />
</form>




Additionally, when I save the form, I want the controller to log one message if the form is valid, and another if it is not valid:



var app = angular.module('plunker', ['ngMessages']);
export class BaseController
public mechanicalForm;
public building;
constructor()
this.mechanicalForm = ;
this.building =
'numberOfChillers': 0
;


public save()
if (this.mechanicalForm.$valid)
console.log("This worked");

else
console.log("This did not work");



app.controller('BaseController', BaseController);


But it seems like my controller is not able to see the form at all. According to everything I have read I seem to be writing the code correctly. My two questions are:



1: Why will the ng-message not disappear when my input is valid?



2: Why is my controller not able to see my form object?



Here is a code pen Demonstrating my issue. I am using AngularJS 1.5.3



For reference, here are the resources I have referred to so far:



How to use ng-messages



AngularJS form and control state



Using 'controller as' syntax



common issues with ng-messages










share|improve this question
























  • Use basic debugging techniques to see the value of the form when the save button is clicked.

    – georgeawg
    Mar 8 at 19:38












  • I have already tried that approach only to see that the form value is either an empty object if I define it in the constructor of my controller or undefined if it is defined in the template.

    – Nikhil Badami
    Mar 8 at 22:09













0












0








0








I know this question has been asked many times but none of the answers/resources have been able to help me.



I am trying to make a simple form in angular that will take a number and display a message if it is negative:



<div layout-padding ng-controller="BaseController as vm">
<form name="vm.mechanicalForm">
<input type="number" min="0" name="test" ng-model="vm.building.numberOfChillers" required />
<div ng-messages="vm.mechanicalForm.number.$error">
<div ng-message="min">
Test worked
</div>
</div>
<input type="button" ng-click="vm.save()" value="Save" />
</form>




Additionally, when I save the form, I want the controller to log one message if the form is valid, and another if it is not valid:



var app = angular.module('plunker', ['ngMessages']);
export class BaseController
public mechanicalForm;
public building;
constructor()
this.mechanicalForm = ;
this.building =
'numberOfChillers': 0
;


public save()
if (this.mechanicalForm.$valid)
console.log("This worked");

else
console.log("This did not work");



app.controller('BaseController', BaseController);


But it seems like my controller is not able to see the form at all. According to everything I have read I seem to be writing the code correctly. My two questions are:



1: Why will the ng-message not disappear when my input is valid?



2: Why is my controller not able to see my form object?



Here is a code pen Demonstrating my issue. I am using AngularJS 1.5.3



For reference, here are the resources I have referred to so far:



How to use ng-messages



AngularJS form and control state



Using 'controller as' syntax



common issues with ng-messages










share|improve this question
















I know this question has been asked many times but none of the answers/resources have been able to help me.



I am trying to make a simple form in angular that will take a number and display a message if it is negative:



<div layout-padding ng-controller="BaseController as vm">
<form name="vm.mechanicalForm">
<input type="number" min="0" name="test" ng-model="vm.building.numberOfChillers" required />
<div ng-messages="vm.mechanicalForm.number.$error">
<div ng-message="min">
Test worked
</div>
</div>
<input type="button" ng-click="vm.save()" value="Save" />
</form>




Additionally, when I save the form, I want the controller to log one message if the form is valid, and another if it is not valid:



var app = angular.module('plunker', ['ngMessages']);
export class BaseController
public mechanicalForm;
public building;
constructor()
this.mechanicalForm = ;
this.building =
'numberOfChillers': 0
;


public save()
if (this.mechanicalForm.$valid)
console.log("This worked");

else
console.log("This did not work");



app.controller('BaseController', BaseController);


But it seems like my controller is not able to see the form at all. According to everything I have read I seem to be writing the code correctly. My two questions are:



1: Why will the ng-message not disappear when my input is valid?



2: Why is my controller not able to see my form object?



Here is a code pen Demonstrating my issue. I am using AngularJS 1.5.3



For reference, here are the resources I have referred to so far:



How to use ng-messages



AngularJS form and control state



Using 'controller as' syntax



common issues with ng-messages







html angularjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 23:01







Nikhil Badami

















asked Mar 8 at 19:07









Nikhil BadamiNikhil Badami

104




104












  • Use basic debugging techniques to see the value of the form when the save button is clicked.

    – georgeawg
    Mar 8 at 19:38












  • I have already tried that approach only to see that the form value is either an empty object if I define it in the constructor of my controller or undefined if it is defined in the template.

    – Nikhil Badami
    Mar 8 at 22:09

















  • Use basic debugging techniques to see the value of the form when the save button is clicked.

    – georgeawg
    Mar 8 at 19:38












  • I have already tried that approach only to see that the form value is either an empty object if I define it in the constructor of my controller or undefined if it is defined in the template.

    – Nikhil Badami
    Mar 8 at 22:09
















Use basic debugging techniques to see the value of the form when the save button is clicked.

– georgeawg
Mar 8 at 19:38






Use basic debugging techniques to see the value of the form when the save button is clicked.

– georgeawg
Mar 8 at 19:38














I have already tried that approach only to see that the form value is either an empty object if I define it in the constructor of my controller or undefined if it is defined in the template.

– Nikhil Badami
Mar 8 at 22:09





I have already tried that approach only to see that the form value is either an empty object if I define it in the constructor of my controller or undefined if it is defined in the template.

– Nikhil Badami
Mar 8 at 22:09












1 Answer
1






active

oldest

votes


















0














<div layout-padding ng-controller="BaseController as vm">
<form name="vm.mechanicalForm">
<input type="number" min="0" name="test" ng-model="vm.building.numberOfChillers" required />
̶<̶d̶i̶v̶ ̶n̶g̶-̶m̶e̶s̶s̶a̶g̶e̶s̶=̶"̶v̶m̶.̶m̶e̶c̶h̶a̶n̶i̶c̶a̶l̶F̶o̶r̶m̶.̶n̶u̶m̶b̶e̶r̶.̶$̶e̶r̶r̶o̶r̶"̶>̶
<div ng-messages="vm.mechanicalForm.test.$error">
<div ng-message="min">
Test worked
</div>
</div>
<input type="button" ng-click="vm.save()" value="Save" />
</form>


The DEMO on PLNKR






share|improve this answer

























  • That was a silly thing for me to miss. But that does not fix my problem. I realize the plunker is not working. This code pen illustrates my problem.

    – Nikhil Badami
    Mar 8 at 22:59











  • Works in this DEMO on PLNKR.

    – georgeawg
    Mar 8 at 23:48











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069492%2funable-to-get-ng-message-to-disappear-when-form-is-valid-or-reference-form-in-co%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














<div layout-padding ng-controller="BaseController as vm">
<form name="vm.mechanicalForm">
<input type="number" min="0" name="test" ng-model="vm.building.numberOfChillers" required />
̶<̶d̶i̶v̶ ̶n̶g̶-̶m̶e̶s̶s̶a̶g̶e̶s̶=̶"̶v̶m̶.̶m̶e̶c̶h̶a̶n̶i̶c̶a̶l̶F̶o̶r̶m̶.̶n̶u̶m̶b̶e̶r̶.̶$̶e̶r̶r̶o̶r̶"̶>̶
<div ng-messages="vm.mechanicalForm.test.$error">
<div ng-message="min">
Test worked
</div>
</div>
<input type="button" ng-click="vm.save()" value="Save" />
</form>


The DEMO on PLNKR






share|improve this answer

























  • That was a silly thing for me to miss. But that does not fix my problem. I realize the plunker is not working. This code pen illustrates my problem.

    – Nikhil Badami
    Mar 8 at 22:59











  • Works in this DEMO on PLNKR.

    – georgeawg
    Mar 8 at 23:48















0














<div layout-padding ng-controller="BaseController as vm">
<form name="vm.mechanicalForm">
<input type="number" min="0" name="test" ng-model="vm.building.numberOfChillers" required />
̶<̶d̶i̶v̶ ̶n̶g̶-̶m̶e̶s̶s̶a̶g̶e̶s̶=̶"̶v̶m̶.̶m̶e̶c̶h̶a̶n̶i̶c̶a̶l̶F̶o̶r̶m̶.̶n̶u̶m̶b̶e̶r̶.̶$̶e̶r̶r̶o̶r̶"̶>̶
<div ng-messages="vm.mechanicalForm.test.$error">
<div ng-message="min">
Test worked
</div>
</div>
<input type="button" ng-click="vm.save()" value="Save" />
</form>


The DEMO on PLNKR






share|improve this answer

























  • That was a silly thing for me to miss. But that does not fix my problem. I realize the plunker is not working. This code pen illustrates my problem.

    – Nikhil Badami
    Mar 8 at 22:59











  • Works in this DEMO on PLNKR.

    – georgeawg
    Mar 8 at 23:48













0












0








0







<div layout-padding ng-controller="BaseController as vm">
<form name="vm.mechanicalForm">
<input type="number" min="0" name="test" ng-model="vm.building.numberOfChillers" required />
̶<̶d̶i̶v̶ ̶n̶g̶-̶m̶e̶s̶s̶a̶g̶e̶s̶=̶"̶v̶m̶.̶m̶e̶c̶h̶a̶n̶i̶c̶a̶l̶F̶o̶r̶m̶.̶n̶u̶m̶b̶e̶r̶.̶$̶e̶r̶r̶o̶r̶"̶>̶
<div ng-messages="vm.mechanicalForm.test.$error">
<div ng-message="min">
Test worked
</div>
</div>
<input type="button" ng-click="vm.save()" value="Save" />
</form>


The DEMO on PLNKR






share|improve this answer















<div layout-padding ng-controller="BaseController as vm">
<form name="vm.mechanicalForm">
<input type="number" min="0" name="test" ng-model="vm.building.numberOfChillers" required />
̶<̶d̶i̶v̶ ̶n̶g̶-̶m̶e̶s̶s̶a̶g̶e̶s̶=̶"̶v̶m̶.̶m̶e̶c̶h̶a̶n̶i̶c̶a̶l̶F̶o̶r̶m̶.̶n̶u̶m̶b̶e̶r̶.̶$̶e̶r̶r̶o̶r̶"̶>̶
<div ng-messages="vm.mechanicalForm.test.$error">
<div ng-message="min">
Test worked
</div>
</div>
<input type="button" ng-click="vm.save()" value="Save" />
</form>


The DEMO on PLNKR







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 8 at 23:48

























answered Mar 8 at 22:19









georgeawggeorgeawg

34.9k115470




34.9k115470












  • That was a silly thing for me to miss. But that does not fix my problem. I realize the plunker is not working. This code pen illustrates my problem.

    – Nikhil Badami
    Mar 8 at 22:59











  • Works in this DEMO on PLNKR.

    – georgeawg
    Mar 8 at 23:48

















  • That was a silly thing for me to miss. But that does not fix my problem. I realize the plunker is not working. This code pen illustrates my problem.

    – Nikhil Badami
    Mar 8 at 22:59











  • Works in this DEMO on PLNKR.

    – georgeawg
    Mar 8 at 23:48
















That was a silly thing for me to miss. But that does not fix my problem. I realize the plunker is not working. This code pen illustrates my problem.

– Nikhil Badami
Mar 8 at 22:59





That was a silly thing for me to miss. But that does not fix my problem. I realize the plunker is not working. This code pen illustrates my problem.

– Nikhil Badami
Mar 8 at 22:59













Works in this DEMO on PLNKR.

– georgeawg
Mar 8 at 23:48





Works in this DEMO on PLNKR.

– georgeawg
Mar 8 at 23:48



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069492%2funable-to-get-ng-message-to-disappear-when-form-is-valid-or-reference-form-in-co%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved