ANGULARJS Implement dynamic Add input box

Source: Internet
Author: User
Tags button type

Summary: First, there is a requirement, that is, I click Add, will dynamically appear to input the input box. We need to define an object, like this,

{spc:{},spctions:[]}

This means that the SPC corresponds to an object, and the spctions corresponds to a list. To achieve the effect of dynamic insertion, we just need to insert an empty correspondence into the list of Spctions {}, which is simple.

Finally, you need to insert two tables, which is equivalent to a one-to-many relationship. This should be understood. Of course, here we focus on the principle of dynamic insertion and how angular is implemented.

JS Code

// Add Spec options line    $scope. addtablerow=function() {        $scope. Entity.specificationOptionList.push ({});    }

HTML code

<tbody>                      <tr ng-repeat= "Pojo in Entity.specificationoptionlist" >                                                       <td>                                <input  class= "Form-control" placeholder= "size Options" ng-model= "Pojo.optionname" >                            </td>                            <td>                                < Input  class= "Form-control" placeholder= "Sort" ng-model= "pojo.orders" >                            </td>                            <td>                                <button type= "button" class= "btn btn-default" title= "delete" ng-click= "Deletablerow ($index)" ><i class= "FA Fa-trash-o "></i> Delete </button>                            </td>                      </tr>                    </tbody>

Say something you need to be aware of. That's not going to work, because it'll be an error.

Entity.specificationoptionlist    is undefined, so we're going to initialize it. It is best to initialize on the click on the New button because ... (I'll see if I try.)
Add this line to the button
Ng-click= "entity={specificationoptionlist:[]}"

If deleted, the principle is to pass an array coordinate and delete it in the array. Gets the coordinates that traverse the list $index gets


OK super simple. Don't know the message have to say two-way binding cool dead if you use jquery to Kill your frame charm

ANGULARJS Implement dynamic Add input box

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.