从组件到视图的数据 (Angularjs)
data from component to view (Angularjs)
我确信这很简单,但我似乎无法将信息从组件传递到视图。我在 Whosebug 和 google 上搜索了这个,但找不到解决方案。
这里是 javascript 组件调用 API,它将信息打印到控制台,
component.js
$ctrl.getInformation = function() {
// call php controller.
// return audits for html file.
$http.get(`path/to/getInformation/${$ctrl.path.idTo}`).then(function(responseState) {
console.log('sucessfull callback from server', responseState.data);
return responseState.data;
});
}
查看template.html 文件:
<tr ng-repeat="i in vm.getInformation">
<td> {{ vm.getInformation().data[i].Date }}</td>
<td> {{ vm.getInformation(responseState.data[i].Date) }} </td>
</tr>
谁能告诉我为什么它不将信息从组件渲染到模板文件?
您需要将获取的数据分配给 $scope 变量或控制器中的变量,然后才能循环它。在您的控制器中,您需要将代码更改为
$ctrl.information = [];
$ctrl.getInformation = function() {
$http.get(`path/to/getInformation/${$ctrl.path.idTo}`).then(function(responseState) {
console.log('sucessfull callback from server', responseState.data);
$ctrl.information = responseState.data;
});
}
然后在你的html
<tr ng-repeat="data in vm.information">
<td> {{ data.Date }}</td>
<td> {{ data.whatever) }} </td>
</tr>
我确信这很简单,但我似乎无法将信息从组件传递到视图。我在 Whosebug 和 google 上搜索了这个,但找不到解决方案。
这里是 javascript 组件调用 API,它将信息打印到控制台,
component.js
$ctrl.getInformation = function() {
// call php controller.
// return audits for html file.
$http.get(`path/to/getInformation/${$ctrl.path.idTo}`).then(function(responseState) {
console.log('sucessfull callback from server', responseState.data);
return responseState.data;
});
}
查看template.html 文件:
<tr ng-repeat="i in vm.getInformation">
<td> {{ vm.getInformation().data[i].Date }}</td>
<td> {{ vm.getInformation(responseState.data[i].Date) }} </td>
</tr>
谁能告诉我为什么它不将信息从组件渲染到模板文件?
您需要将获取的数据分配给 $scope 变量或控制器中的变量,然后才能循环它。在您的控制器中,您需要将代码更改为
$ctrl.information = [];
$ctrl.getInformation = function() {
$http.get(`path/to/getInformation/${$ctrl.path.idTo}`).then(function(responseState) {
console.log('sucessfull callback from server', responseState.data);
$ctrl.information = responseState.data;
});
}
然后在你的html
<tr ng-repeat="data in vm.information">
<td> {{ data.Date }}</td>
<td> {{ data.whatever) }} </td>
</tr>