我有一个添加路线表格。我能够从视图到控制器获取距离,描述$scope
值,但是对于一个字段终端站点,在提交表单之前是自动生成的值,在$ scope值中是未定义的。
你有没有人能告诉我什么是错的,这是任何回电/加载问题。
<form class="well form-horizontal" id="addRouteForm" ng-submit="r.addRoute()">
<fieldset>
<!-- Route Description-->
<div class="form-group">
<label class="control-label">Description</label>
<div class="inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-pencil"></i></span>
<textarea name="description" ng-model="route.description" placeholder="Enter route description" class="form-control" type="text" required></textarea>
</div>
</div>
</div>
<!-- Route distance-->
<div class="form-group">
<label class="control-label">Route Distance</label>
<div class="inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-road"></i></span>
<input name="distance" ng-model="route.distance" placeholder="12.56 km" class="form-control" type="number" step="00.01" required>
</div>
</div>
</div>
<!-- Route distance-->
<div class="form-group">
<label class="control-label">Terminal stop</label>
<div class="inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-road"></i></span>
<input name="terminalstop" ng-model="route.routeTerminalStop" id="terminalstop" value={{route.routeTerminalStop}} placeholder="Terminal stop" class="form-control" type="text">
</div>
</div>
</div>
</fieldset>
<button type="submit" id="submitRoute" value="addRoute" class="btn btn-warning btn-sm" data-placement="top" ng-disabled="r.isNotLoaded" ng-show="saveRoute">Save <span class="glyphicon glyphicon-send"></span>
</button>
ctrl.js:
vm.addRoute = function () {
vm.isNotLoaded = true;
vm.responseMessage = "";
var route = $scope.route;
var y = document.getElementById("terminalstop").value;
var x = $scope.routeTerminalStop;
通过var y,我能够得到但是var x未定义。路线的终点站是未定义的。