Controller does not see ng-model of Angular JS

0

The CreateCtrl controller is not seeing the ng-model of the input of my form. I can pass values from the controller to the view but I'm not getting the reverse. Where am I going wrong?

Controller:

    .controller('CriarCtrl', function ($scope) {
    $scope.criarDemanda = function () {
        console.log($scope.name);
    }
})

View:

<input type="text" ng-model="name" name="nome" required />
<button class="button button-assertive button-block activated" ng-click="criarDemanda()">Enviar</button>
    
asked by anonymous 19.10.2015 / 21:54

2 answers

3

Try to send an object.

ng-click="demanda.name"

If you have more attributes that go into this demand, just follow this pattern, for example:

ng-click="demanda.quantidade"

Then just pass the demand to the method called in ng-click :

 ng-click="criarDemanda(demanda)

I've tried to find a way to answer your question, and if I explain it the way I "understand" you might get confused.

Take a look here: link

And if you are good at English look at the documentation of the Angular.

    
19.10.2015 / 22:02
1

The ngModel directive is responsible for linking an input, select, textarea, and other controls to a scope property, without the need to pass this information as arguments to any method.

For more information, see link

Following example working correctly.

<!DOCTYPE html>
<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div id="entityScope" ng-app="myApp" ng-controller="CriarCtrl">
    <input type="text" ng-model="name" name="nome" required />
    <button ng-click="criarDemanda()">Enviar</button>
</div>    
<script>
var app = angular.module('myApp', []);
app.controller('CriarCtrl', function ($scope) {
    $scope.criarDemanda = function () {
        console.log($scope.name);
    }
});
</script>

</body>
</html>
    
29.10.2015 / 17:58