banerjee196 banerjee196 - 2 months ago 18
AngularJS Question

Cant get value from ng-model?

im using this account because im logged in on facebook on my other and i dont have my phone with me to do the pass code verification ect..

Anyway.. Im trying to get the value from a ng-model but i just cannot seem to get it no matter what i try. I think i need some other eyes to have a quick look at my code to see if they can work it out, Cheers...

Html:


<div class="form-group"><label class="col-sm-2 control-label">Established :</label>
<div class="col-sm-10"><input type="text" class="form-control" ng-model="established"></div>
</div>

<button class="btn btn-primary " style="float:right;" ng-click="saveApprisalDetails()" type="button"><i class="fa fa-paste"></i> Save</button>


Controller:

$scope.saveApprisalDetails=function(){
var urlgetappraisals = './dbscripts/getAppraisalsByRef.php?ref=' + ref
console.log(urlgetappraisals);
$http({
method: 'GET',
url: urlgetappraisals
}).success(function(data) {

$scope.appraisaldetails = data;
console.log(JSON.stringify(data));

var url = './dbscripts/saveApprisal.php?id=' + data[0].id;
url += '&appraisalCompany=' + appraisalCompany;
url += '&title=' + ref;
url += '&established=' + $scope.established;

console.log(url);

$http({
method: 'GET',
url: url
}).success(function(data) {
})
})
}
}
catch(e){}
}

Answer

Maybe try something different to see if it works, in the begginning of the controller:

$scope.view_data = {};

In the function:

url += '&established=' + $scope.vies_data.established;

And in the view:

<input type="text" class="form-control" ng-model="view_data.established">

Hope it helps =)