Angular函数从$ http requrest获取数据

时间:2017-05-24 06:05:22

标签: angularjs

我需要通过$ http请求获取数据,我需要将它用于我的表单的编辑值。

示例代码

    @Override
protected void configure(HttpSecurity http) throws Exception {
    //http.csrf().disable();
    http
        .csrf().disable()
        .httpBasic().and()
        .authorizeRequests()
            .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
            .anyRequest().authenticated()
            //.and().requiresChannel().anyRequest().requiresSecure()
            .and().httpBasic().authenticationEntryPoint(customBasicAuthenticationEntryPoint)

            .and().addFilter(basicAuthenticationFilter(super.authenticationManagerBean()));
}

2 个答案:

答案 0 :(得分:2)

  

绑定您的$ scope以查看,并使用您的json params创建表单,如此示例,阅读评论



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

app.controller("ctrl", function ($scope) {
   //json
   //uncomment in your local
   //$http.get(base_url + "user/feach_one").then(function (response) {
   //    var json = response;
   //    $scope.form = json;
   //});

   //we didn't have api here: { name: "Test", age: 20 }
   //comment in your local
   var json = { name: "Test", age: 20 }
   $scope.form = json;
});

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
  <form>
      <label>name</label>
        <input type="text" ng-model="form.name"/>
      <label>age</label>
        <input type="text" ng-model="form.age"/>
  </form>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

$scope.basic= {};
$scope.advanced= {};
 $http.get(base_url+"user/feach_one")
    .then(function (response) {
     $scope.basic.name=$scope.json.name;
     $scope.advanced=$scope.json.avanced;
    });