Reputation: 83
I have an error in angular js, when setting application.apikey with response.data.
HTML:
<div class="row">
<div class="form-group col-xs-6">
<label>1:</label>
<input type="text" class="form-control" name="apikey" ng-model="applicationn.apikey"></input>
</div>
<div class="form-group col-xs-6">
<label>2:</label>
<input type="text" class="form-control" name="apikeysecret" ng-model="application.apisecret"></input>
</div>
</div>
AngularJS:
$scope.getApiKey = function () {
$http({
method: 'GET',
url: '/applications/generateApiKey'
}).then(function success(response) {
console.log(response.data),
$scope.application.apikey = response.data.apikey;
});
}
Console:
{id: null, name: null, apikey: "cce4866e0b23c721b1e8d733a4cf48c1", apisecret: "914c87f20473c4fac9fbbab65de6e6b0", custom_data: null}
angular.js:14525 TypeError: Cannot set property 'apikey' of undefined
Upvotes: 0
Views: 465
Reputation: 3232
You have not defined $scope.application
and trying to define its property.
Try this :
$scope.application = {};
$scope.getApiKey = function () {
$http({
method: 'GET',
url: '/applications/generateApiKey'
}).then(function success(response) {
console.log(response.data),
$scope.application.apikey = response.data.apikey;
});
}
Upvotes: 1