开机自检后显示的数据与AngularJS [英] Show data after POST with AngularJS

查看:124
本文介绍了开机自检后显示的数据与AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着表明我已经照耀的数据,一个POST动作后。但是,这是行不通的。我怎样才能做到这一点?

Im trying show the data that I have enterd, after an POST-action. But it does not work. How can I accomplish this?

下面是我的HTML:

<div ng-controller="Test">
<div class="container">
<div class="col-sm-9 col-sm-offset-2">

    <div class="page-header"><h1>Testar</h1></div>
    <table class="table table-striped table-condensed">
    <thead>
        <tr>
            <th>Namn</th>
            <th>Efternamn</th>
            <th>E-post</th>
         </tr>
    </thead>
        <tr ng-repeat="info in test.data"><td>{{info.namn}}</td><td>{{info.efternamn}}</td><td>{{info.email}}</td></tr>
    </table>

    <form name="userForm" ng-submit="submitForm(userForm.$valid)" novalidate> <!-- novalidate prevents HTML5 validation since we will be validating ourselves -->
        <div class="form-group" ng-class="{'has-error' : userForm.name.$invalid && !userForm.name.$pristine, 'has-success' : userForm.name.$valid }">
            <label>Name</label>
            <input type="text" name="name" class="form-control" ng-model="form.name" required>
            <p ng-show="userForm.name.$invalid && !userForm.name.$pristine" class="help-block">Fel namn</p>
        </div>

        <div class="form-group" ng-class="{'has-error' : userForm.username.$invalid && !userForm.username.$pristine, 'has-success' : userForm.username.$valid && !userForm.username.$pristine}">
            <label>Username</label>
            <input type="text" name="username" class="form-control" ng-model="form.username" ng-minlength="3" ng-maxlength="8">
            <p ng-show="userForm.username.$error.minlength" class="help-block">För kort</p>
            <p ng-show="userForm.username.$error.maxlength" class="help-block">För långt</p>

        </div>

        <div class="form-group" ng-class="{'has-error' : userForm.email.$invalid && !userForm.email.$pristine, 'has-success' : userForm.email.$valid && !userForm.email.$pristine}">
            <label>Email</label>
            <input type="email" name="email" class="form-control" ng-model="form.email">
            <p ng-show="userForm.email.$invalid && !userForm.email.$pristine" class="help-block">Ange korrekt e-post</p>
        </div>      

        <button type="submit" class="btn btn-primary">Lägg till</button>
    </form>
</div>
</div>

下面是我的控制器:

as.controller('Test', function($scope, $http, $rootScope)
    {   

        $http.get($rootScope.appUrl + '/nao/test/test')
            .success(function(data, status, headers, config) {
                $scope.test = data;
        });

        $scope.form = {};

        $scope.submitForm = function(isValid) {
            if(isValid) 
            {   
                $http.post($rootScope.appUrl + '/nao/test', $scope.form)
                .success(function(data, status, headers, config) {
                    console.log(data);
                    $scope.test = data;
                }).error(function(data, status) {

                })
            }
        };
    });

我如何查看我在输入字段中输入,之后提交的数据?正如你所看到的,我已经尝试设置$ scope.test =数据,但不工作。

How can I view the data that I entered in the input fields, after the submit? As you can see, I've tried to set $scope.test = data, but that don't work.

推荐答案

请在这里看到: http://jsbin.com/gagiwo/1/edit?js,output

    as.controller('Test', function($scope, $http, $rootScope)
            {   

                $http.get($rootScope.appUrl + '/nao/test/test')
                    .success(function(data, status, headers, config) {
                        $scope.test = data;
                });

                $scope.form = {};

  $scope.submitForm = function(isValid) {
          if(isValid) 
            {   
              $http.post($rootScope.appUrl + '/nao/test', $scope.form)
                .success(function(data, status, headers, config) {
                  console.log(data); <-- data is object returned from server
                   $scope.datePosted = $scope.form; <-- $scope.form is your object posted to server

                }).error(function(data, status) {

                  $scope.datePosted =$scope.form;
                });


            }
        };
            });

这篇关于开机自检后显示的数据与AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆