rafi
rafi

Reputation: 1543

How to edit value (generated by PHP) in angularjs

I have a form which is being used to edit some information. Form input fields get value generated by PHP. Before, I was using jQuery to edit and calculate values and get total value. Now I want to remove jQuery and use AngularJS during form edit. After I have searched in web for this editing solution, I could not find anything. Is it possible to edit values generated by PHP with AngularJS and calculate sum of values?

EDIT

Can I get those values in angularJS? If I try to get those values with ng-model, it gets nothing and makes those fields blank.

Upvotes: 1

Views: 296

Answers (1)

BKM
BKM

Reputation: 7079

You could use an API call to your backend service to fetch the values and use those values in your AngularJS application.

Suppose you have a form like this in your application.

<form ng-controller="formController" ng-submit="someAction" method="post">
<input type = "text" ng-model="email"/>
</form>

And you want to populate value from your PHP to this email field. You can do it by making an API call to your backend service like this;

In your AngularJS controller;

var app = angular.module('YourApp');

app.controller('formController', function ($scope, $http) {
$http.get('API call to fetch data').success(function (data) {
  $scope.email = data.email;
});
});

Hope it helps.

Upvotes: 3

Related Questions