简体   繁体   中英

AngularJS - ng-model not working with bootstrap directives

I am using AngularJS for my project and I am new to it. But I liked its features and very convenient for development as well. But I came up with the following issue and didn't know to get out of it.

I have a multi view application. The following code is a part of signup view. This view gets displayed when the signup button is pressed. Now the issue is, in the 4th and 5th line below, I have attached a ng-model attribute to and I am able to print the number obtained using {{num}} directive. However, the ng-model num2 below is not getting displayed as above. All I get is the static text {{num2}} being displayed. Why is it not working like the previous case?

<form role='form' action='#/app/register_db' method='post'>
    <h1><small><b>Sign Up Information<b></small></h1>
    <br>
    <input type='text' ng-model='num'>
    <h1>{{num}}</h1>
    <div class='row'>
        <input type='text' ng-model='num2'>
        <h1>{{num2}}</h1>
        <div class='col-xs-5'>
            <input type="text" class='form-control' id="fn" name='firstname' ng-model='ng-firstname' placeholder="First Name">
        </div>
    </div>
...
...

I am new to AngularJS and I am very quickly grasping concepts. So if I am missing something, then please guide me through the right path and help me fix this issue.

I am using angularJS and Bootstrap CSS.

Thanks.

You should get the following error message in your browser's console:

[ngModel:nonassign] Expression 'ng-firstname' is non-assignable. Element: <input type="text" class="form-control" id="fn" name="firstname" ng-model="ng-firstname" placeholder="First Name">

As ng-model="ng-firstname" is not a reference by name, but an expression AngularJS will try to evaluate, so simply not using a dash will fix that. What happens when you break the code there is AngularJS basically stops, and anything else AngularJS would usually do in elements that follow, simply doesn't happen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM