0

i fetch from json and set the value to my angular ionic app. my textbox holds the value. but im unable to get the textbox value to controller. this is how i have done it

controller.js

$http.post("http://www.fooget.com/mydetails.php).success(function(details){
$scope.mydetails= details;
});

and i set the value to my html page

<form>
<div  ng-repeat="data in details|limitTo:1">
<p>{{data.f_name}}</p> <!--displays the value-->
<input type="text" ng-model="v.name" value="{{data.f_name}}"/> <!--empty values-->
<input type="text" ng-model="v.id" value="{{data.id}}"/> <!--empty values-->
<button ng-click="push(v)">
</form>

on form click i dont get the textbox values to my controller, im trying to get the vaules to the controller. it doesnt appear

$scope.push= function (v) { 
var push_name = v.name; // empty values
var push_id = v.id; // empty values
}
4
  • have you mentioned ng-controller to right one? Commented Mar 25, 2015 at 13:38
  • yes both comes under one controller Commented Mar 25, 2015 at 13:55
  • @Naz141 You have mentioned details in ng-repeat. Hope it should be mydetails as you have defined $scope.mydetails in your controller Commented Mar 25, 2015 at 14:00
  • that is my mistake in typing, anyways i still face the problem in not getting the value to the textboxes Commented Mar 26, 2015 at 6:26

1 Answer 1

1

Also in your HTML:

<div  ng-repeat="data in details|limitTo:1">

It should be

<div  ng-repeat="data in mydetails|limitTo:1">

as you have $scope.mydetails and not details

The real problem is in initializing the values for ng-model:

As you're just setting the value attribute in input text, it's not assigned to the ng-model. Use ng-init directive to set it in the view.

<input type="text" ng-model="v.name" ng-init="v.name=data.f_name"/> 
<input type="text" ng-model="v.id"  ng-init="v.name=data.id"/>

This will work for you.

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

1 Comment

this never works, <input type="text" ng-model="v.name" ng-init="v.name=data.f_name"/> this input does not view the value or cannot get the value to controller

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.