Form data does not appear

1

I'm developing an app on Ionic, an address book.

After the form , I added a console.log (address) in controler to see the data, I click the save button and the data does not appear and still says console.log (address) is undefined .

Follow the codes

Html:

<ion-view title="Endereco" hide-back-button="true">
<ion-content overflow-scroll="true" padding="true" scroll="false" class="has-header">
    <form name="enderecoForm" class="list">
        <ion-list>
            <div ng-controller="enderecoCtrl">
                <label class="item item-input">
                    <input type="text" ng-model="endereco.cep" ng-blur="pegaCep()" placeholder="CEP">
                </label>
                <label class="item item-input">
                    <input type="text" ng-model="endereco.uf" placeholder="Estado">
                </label>
                <label class="item item-input">
                    <input type="text" ng-model="endereco.cidade" placeholder="Cidade">
                </label>
                <label class="item item-input">
                    <input type="text" ng-model="endereco.bairro" placeholder="Bairro">
                </label>
                <label class="item item-input">
                    <input type="text" ng-model="endereco.logradouro" placeholder="Logradouro">
                </label>
            </div>
        </ion-list>
        <button class="button button-stable button-block" ng-click="adicionarEndereco(endereco)">Salvar</button>
    </form>
</ion-content>

Controller:

angular.module('app.controllers', [])

.controller('loginCtrl', function($scope) {

})

.controller('enderecoCtrl', function ($scope, $http) {
$scope.pegaCep = function () { 
$http.get("php/pegaCep.php?cep="+$scope.endereco.cep).success(function (endereco){
        $scope.endereco = endereco;
    });
 }

$scope.adicionarEndereco = function (endereco){
    console.log(endereco);

}
})
    
asked by anonymous 27.01.2016 / 01:21

1 answer

0

ng-controller="enderecoCtrl" must cover every form up to the submit button.

See that button submit is outside the scope of the controller, it is not known.

See My Solution. Put ng-controller="addressCtrl" in ion-content

<ion-view title="Endereco" hide-back-button="true">
<ion-content overflow-scroll="true" padding="true" scroll="false" class="has-header" ng-controller="enderecoCtrl">
    <form name="enderecoForm" class="list">
        <ion-list>
            <div>
                <label class="item item-input">
                    <input type="text" ng-model="endereco.cep" ng-blur="pegaCep()" placeholder="CEP">
                </label>
                <label class="item item-input">
                    <input type="text" ng-model="endereco.uf" placeholder="Estado">
                </label>
                <label class="item item-input">
                    <input type="text" ng-model="endereco.cidade" placeholder="Cidade">
                </label>
                <label class="item item-input">
                    <input type="text" ng-model="endereco.bairro" placeholder="Bairro">
                </label>
                <label class="item item-input">
                    <input type="text" ng-model="endereco.logradouro" placeholder="Logradouro">
                </label>
            </div>
        </ion-list>
        <button class="button button-stable button-block" ng-click="adicionarEndereco(endereco)">Salvar</button>
    </form>
</ion-content>
    
02.02.2016 / 23:13