Angular.js 值未保存在文本框的范围内
Angular.js values not being saved in the scope from textbox
我有这个 html 标记:
<div data-ng-controller="VehicleProfileController">
<modal title="Add Vehicle Info" visible="showVehicleInfo">
<div class="container">
<div class="col-xs-4">
<div class="row">
Title <input type="text" ng-model="NewVMPTitle" class="form-control"/>
Miles <input type="text" ng-model="NewVMPMiles" class="form-control"/>
</div>
<div class="row">
<button ng-click="addVehicleData()" class="btn btn-success pull-right">Save</button>
</div>
</div>
</div>
</modal>
</div>
然后在控制器中我有这个:
$scope.addVehicleData = function () {
alert($scope.NewVMPTitle + ' ' + $scope.NewVMPMiles);
};
NEWVMPTitle 和 NewVPMMiles 都是空的,我是不是遗漏了什么?
我认为最好用 ng-model 将参数解析到控制器,而不是使用范围从 ng-model 中捕获值
Title <input type="text" ng-model="item.title" class="form-control"/>
Miles <input type="text" ng-model="item.miles" class="form-control"/>
<button ng-click="addVehicleData(item)" class="btn btn-success pull-right">Save</button>
这是 js
$scope.addVehicleData = function (item) {
alert(item.title + ' ' + item.miles);
};
我有这个 html 标记:
<div data-ng-controller="VehicleProfileController">
<modal title="Add Vehicle Info" visible="showVehicleInfo">
<div class="container">
<div class="col-xs-4">
<div class="row">
Title <input type="text" ng-model="NewVMPTitle" class="form-control"/>
Miles <input type="text" ng-model="NewVMPMiles" class="form-control"/>
</div>
<div class="row">
<button ng-click="addVehicleData()" class="btn btn-success pull-right">Save</button>
</div>
</div>
</div>
</modal>
</div>
然后在控制器中我有这个:
$scope.addVehicleData = function () {
alert($scope.NewVMPTitle + ' ' + $scope.NewVMPMiles);
};
NEWVMPTitle 和 NewVPMMiles 都是空的,我是不是遗漏了什么?
我认为最好用 ng-model 将参数解析到控制器,而不是使用范围从 ng-model 中捕获值
Title <input type="text" ng-model="item.title" class="form-control"/>
Miles <input type="text" ng-model="item.miles" class="form-control"/>
<button ng-click="addVehicleData(item)" class="btn btn-success pull-right">Save</button>
这是 js
$scope.addVehicleData = function (item) {
alert(item.title + ' ' + item.miles);
};