我的代码有问题。我正在显示数据库中的数据并将其加载到我的视图中。所有字段都正常工作,它们具有正确的输入值。但是在我的一个输入字段中,我无法显示数据库中的值。
这是我的一些代码:
我的表单输入
<div class="row">
<div class="form-group">
<label>Set(%): </label>
<input type="number" class="form-control text-right" ng-model="quotelist.vat_rate" />
</div>
</div>
然后我有一个像这样的JS:
//CALL OUR MODULE AND LOAD SOME MODULES
var quotationList = angular.module('quotation_list', ['jsonFormatter','ui.bootstrap','ckeditor']);
quotationList.controller('quoteListCtrl', function($scope, $http) {
var quoteList = this;
//initialize value for header
quoteList.receiver = "<?php echo $quotation['receiver_name']; ?>";
quoteList.reference_no = <?php echo $quotation['reference_no']; ?>;
quoteList.address = "<?php echo $quotation['address']; ?>";
quoteList.project_name = "<?php echo $quotation['project_name']; ?>";
quoteList.vat_rate = <?php echo $totals['vat_rate']; ?>; //HERES MY PROBLEM. IN MY DATABASE RESULT IT SHOULD BE 12 BUT I CAN'T DISPLAY IT IN THE FORM INPUT
我尝试删除输入中的ng-model并将值直接打印到表单输入并显示。
这就是我的所作所为:
<div class="row">
<div class="form-group">
<label>Set(%): </label>
<input type="number" class="form-control text-right" value="<?php echo $totals['vat_rate']; ?>" />
</div>
</div>
我不知道我的错误在哪里。我仍然是有角度的新人。
答案 0 :(得分:0)
尝试像这样定义变量:
//CALL OUR MODULE AND LOAD SOME MODULES
var quotationList = angular.module('quotation_list', ['jsonFormatter','ui.bootstrap','ckeditor']);
quotationList.controller('quoteListCtrl', function($scope, $http) {
$scope.quoteList = {};
//initialize value for header
$scope.quoteList.receiver = "<?php echo $quotation['receiver_name']; ?>";
$scope.quoteList.reference_no = <?php echo $quotation['reference_no']; ?>;
$scope.quoteList.address = "<?php echo $quotation['address']; ?>";
$scope.quoteList.project_name = "<?php echo $quotation['project_name']; ?>";
$scope.quoteList.vat_rate = <?php echo $totals['vat_rate']; ?>; //HERES MY PROBLEM. IN MY DATABASE RESULT IT SHOULD BE 12 BUT I CAN'T DISPLAY IT IN THE FORM INPUT
在你看来:
ng-controller="quoteListCtrl"
答案 1 :(得分:0)
正如Jax所提到的,您需要在控制器中使用$scope
将数据绑定到Web视图。
所以在控制器视图中使用$ scope来绑定数据:
$scope.quoteList.vat_rate = quoteList.vat_rate;
并将其绑定到您的网络视图:
<input type="number" class="form-control text-right" ng-model="quotelist.vat_rate" />
希望这有帮助!