I have my html like this:
<form ng-submit="addNews(news)" ng-controller='FormController'>
<input type="text" placeholder="autor" name="autor" ng-model="todos.autor">
<input type="submit" value="click">
{{todos.autor}}
{{todos}}
<span> <var>result:</var> <mark>{{result}}</mark></span>
</form>
using the ng-model directive for the input(as you can see "todos.autor")
my controller (FormController) like this:
$scope.addNews = function(news){
$http.post('send_data.php', {'autor': $scope.todos.autor}).
success(function(data, status) {
$scope.status = status;
$scope.data = data;
$scope.result = data;
})
and finally my php (send_data):
<?php
$data = json_decode(file_get_contents("php://input"));
echo $data->autor;
?>
when the user clicks on submit I call the addNews function from my controller, this function should send the data the user write in the input, then on success the $scope.result will contains the info and finally the result will be mark up in the html (<mark>{{result}}</mark>) (a simple example).
The problem is that no result is shown unless I change my ng-model from todos.autor to simple autor and in the controller change from {'autor': $scope.todos.autor} to {'autor':$scope.autor} (I verified this) I really need to have the todos.autor and not a simple autor
how do I achive the controlled send the data in this way? thanks
$scope.todos = {}in your controller?