Angular-Js ng-model 不接受值

Angular-Js ng-model not accepting values

请检查这段代码。我正在尝试从 UI 获取值,但它未定义。它各自的代码如下。当我在控制台中打印值时,它即将 'undefined'.

UI代码-

<table class="table table-bordered table-striped container">
                    <tr>
                        <td>First Name:</td>
                        <td><input type="text" ng-model="user.firstName"/></td>
                    </tr>
                    <tr>
                        <td>Last Name:</td>
                        <td><input type="text" ng-model="user.lastName"/></td>
                    </tr>
                    <tr>
                        <td>Email:</td>
                        <td><input type="text" ng-model="user.email"/></td>
                    </tr>
                    <tr>
                        <td>Mobile:</td>
                        <td><input type="text" ng-model="user.mobile"/></td>
                    </tr>
                    <tr>
                        <td><br/><button ng-click="addUser()" class="btn-panel-big">Add New User</button></td>
                    </tr>
                </table>

控制器代码-

$scope.addUser = function addUser() {
         console.log("["+user.firstName+"]");
         $http.post(urlBase + 'users/insert/'+$scope.user)
            .success(function(data) {
             $scope.users = data;   
             $scope.user="";             
            });
        };

你能告诉我哪里出了问题吗?我想将值存储在单个对象中,然后将其发送到后端基于 rest 的控制器。

您是否已将您的用户对象初始化为空对象? 例如。 var 用户 = {} 或 $scope.user = {}

使用$scope.user获取用户对象。

console.log("[" + $scope.user.firstName + "]");

也有可能下一行应该是

$http.post(urlBase + 'users/insert/', $scope.user)

希望对您有所帮助

问题在于正确设置范围变量。