简体   繁体   中英

AngularJS 1.3 Migration Not Working

I have updated my script code to the following after reading about documentation on migrating from 1.2 to 1.3 .

var app = angular.module("APP", []);

app.controller('Ctrl', function ($scope) {

$scope.id = [{
    id: 'id #1'
}];

$scope.addNewId = function () {
    var newId = $scope.id.length + 1;
    $scope.id.push({
        'id': 'id #' + newId
    });
};

$scope.removeId = function (index) {
    if (index >= 1) {
        $scope.id.splice(index, 1);
    }
};

});

This is the code for the form:

<!DOCTYPE html>
<html lang = "en" ng-app = "APP">
<head>
    <meta charset = "utf-8">
    <title>Add New ID</title>
    <link rel="stylesheet" href="form.css">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"></script>
    <script type = "text/javascript" src = "form.js"></script>
</head>
<body ng-controller="Ctrl">
    <section>
        <h1>Add New Stuff</h1>
            <form name = "form" id = "form">
            <div ng-model = "indiv">
                <fieldset class="ids" data-ng-repeat="indiv in id">
                    <legend>ID</legend>

                    <label for="name">Name:</label>
                    <input type="text" name="name" id="name" size="60">&nbsp

                    <label for="age">Age:</label>
                    <input type="text" name="age" id="age" size="60">&nbsp

                    <button type="button" name="lookup" id="lookup">LOOKUP</button>&nbsp


                    <button class="remove" ng-click="removeId($index)">Remove ID</button><br>
                </fieldset>

                <br>
                <button class="addfields" ng-click="addNewId()">Add ID</button>

            </div>

            <input type="submit" name="submit" id = "submit" value="SUBMIT">
        </form>
    </section>
</body>

It is supposed to add a new set of input fields to a form. Please help

An id attribute can't contain space nor sharp character here you are setting :

{id: 'id #1'}

May be a part of the answer if you're attributing this value to the id of each input in your ng-repeat.

can you show us the form ?

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