1

I'm making a form to edit information in a database, this form is working, he's taking the information depending on what I select, however it is not showing in text inputs on the page.

I know the information that i'm getting is the right information because I can see on the console and also in the attribute 'value', although not appear on the page.

This page have two inputs text:

  <label for="meetingPoint">Name:</label>
  <input type="text" class="form-control" name="name" rows="5" ng-value="{{ data[0].name }}" ng-model="formData.name" />

  <label for="meetingPoint">Meeting Point:</label>
  <input type="text" class="form-control" name="meetingPoint" rows="5" ng-value="{{ data[0].meetingPoint }}" ng-model="formData.meetingPoint" />

I want be able to see the information on the page and still send to my formData scope, but i'm very lost, is the first time that i'm using the Angular.

This is my controller:

var event = $routeParams.evento;
$scope.data;
$scope.submitForm;
$scope.formData = {};

$http.get('/api/data/event/edit/' + event)
  .success(function (data, status, headers, config) {
    $scope.data = data;
    console.log(data);
  })
  .error(function (data, status, headers, config) {
    $scope.data = data;
  });

$scope.processForm = function () {
  console.log($scope.formData._id);
  $http({
      method: 'PUT',
      url: '/api/data/event/edit' + $scope.formData._id,
      data: $scope.formData,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    })
    .success(function (data) {
      console.log(data);

      if (!data.success) {
        $scope.errorName = data.errors.name;
      } else {
        $scope.message = data.message;
      }
    });
};

So i'm getting the event that i want, them i'm trying to show the information with ng-value, but isn't working, and also edit my formData object.

Can someone give me a hand here? :)

Thanks!!!!

1
  • You should only use the ng-model, it provides you with a two-way binding to the model value Commented Apr 20, 2015 at 4:56

1 Answer 1

1
ng-value="{{ data[0].name }}"

Angular DOCS:: ng-value is not appropriate for input text

Binds the given expression to the value of or input[radio], so that when the element is selected, the ngModel of that element is set to the bound value.

You must use ng-model for input text box.

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

2 Comments

i get it!.. i can use ng-model to show and to send the editions to my server.. ok, thanks!!!
i cant.. waiting 2 min.. haha