0

I have only one text field

 <input type="text" name="groupname" value="">

I want display groupname in above textbox using angularjs

app.controller('get_group_name', function($scope, $http) {
    $http.get(site_url +    'admin/Usergroup_controller/get_available_user/1')
.then(function (response) {$scope.names = response.data.records;});

});

I am getting json data like

[{"groupname":"Bharat"}]

Only one record

How can I get this data in textbox.

3 Answers 3

2
<input type="text" name="groupname" ng-model = "names[0].groupname">

Ng-model is used to bind data from controller to view. I will suggest you to visit angular documentation for better understanding of Angularjs.

FIDDLE: http://jsfiddle.net/Lvc0u55v/1452/

Sign up to request clarification or add additional context in comments.

1 Comment

Yes. no issue with controller.
1
<input type="text" name="groupname" value="" ng-model="groupname">

then in the promise just use the $scope variable:

app.controller('get_group_name', function($scope, $http) {
$http.get(site_url + 'admin/Usergroup_controller/get_available_user/1')
.then(function (response) {$scope.names = response.data.records; 
$scope.groupname = response.data.records.groupname;

});

1 Comment

try with:$scope.groupname = response[0].groupname;
0
<input type="text" name="groupname" ng-model="name">

Then in controller :

app.controller('get_group_name', function($scope, $http) {
   $http.get(site_url + 'admin/Usergroup_controller/get_available_user/1')
  .then(function (response) {
              $scope.names = response.data.records; 
              $scope.name = response.data.name;
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.