我们可以使用控制器中的ng-init初始化值,该值从服务器端(php)到达angularjs中的控制器

时间:2015-02-06 12:54:05

标签: php angularjs

的index.html:

<form name="cca">
 <input type="text" ng-model="form.product_id"  ng-init="form.product_id=prod_id">
 <input type="button" ng-click="profile_updated()">
  </form>

在我的控制器中:

$scope.profile_data_init = function() {    $scope.prod_id="hi";    }    //its working fine

但我无法使用controller..code

从服务器端获取init值
 $scope.profile_data_init = function() {

   //alert('uu');
    //console.log($scope.loginform);
    $http.post("ajax/profile_updation.php",{profile_up_init:"profile_init"}).
    success(function(data, status, headers, config) {
    $scope.prod_id=data[0].pid; //json data
    }).error(function(data, status, headers, config) {
         alert("Please Try Again..!");
     });
   }

1 个答案:

答案 0 :(得分:0)

ng-init

中试试您的请求
<form name="cca">
    <input type="text" ng-model="form.product_id"  ng-init="profile_data_init()">
    <input type="button" ng-click="profile_updated()">
</form>

并在成功时设置$scope.form.product_id = $scope.prod_id = data[0].pid;

$scope.profile_data_init = function() {
    $http.post("ajax/profile_updation.php",{profile_up_init:"profile_init"}).
    success(function(data, status, headers, config) {
        $scope.form.product_id = $scope.prod_id = data[0].pid; //json data
    }).
    error(function(data, status, headers, config) {
        alert("Please Try Again..!");
    });
}
相关问题