在使用response.data设置application.apikey时,我在角度js中出错。
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;
});
}
控制台:
{id: null, name: null, apikey: "cce4866e0b23c721b1e8d733a4cf48c1", apisecret: "914c87f20473c4fac9fbbab65de6e6b0", custom_data: null}
angular.js:14525 TypeError: Cannot set property 'apikey' of undefined
答案 0 :(得分:1)
您尚未定义$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;
});
}
并尝试定义其属性。
试试这个:
html, body {
margin: 0;
padding: 0;
overflow-y: hidden;
}
#header {
position: fixed;
background-color: teal;
z-index: 1;
top: 0;
height: 100px;
width: 100%;
}
#main {
position: absolute;
top: 100px;
max-height: 100%;
width: 100%
overflow-y: scroll;
}