我是angularjs的新手, ng-submit 在表单提交后给出旧值
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.myTxt = "You have not yet clicked submit";
$scope.sidebarname = "Vendor";
$scope.myFunc = function () {
$scope.myTxt = "You clicked submit!";
alert($scope.sidebarname);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<form ng-submit="myFunc()">
<input ng-value="sidebarname" type="text">
<input type="submit">
</form>
<p>{{myTxt}}</p>
</div>
表单提交 $ scope.sidebarname 给旧值供应商后,我已经阅读并搜索了它,但没有任何帮助。
任何帮助或建议都会有所帮助
答案 0 :(得分:2)
尝试:
<form ng-submit="myFunc()">
<input ng-model="sidebarname" type="text">
<input type="submit">
</form>
注意:ng-model
ng-value
来自Runtime
答案 1 :(得分:1)
VARIANT
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.myTxt = "You have not yet clicked submit";
$scope.sidebarname = "Vendor";
$scope.myFunc = function () {
$scope.myTxt = "You clicked submit!";
alert($scope.sidebarname);
}
});
答案 2 :(得分:0)
要绑定HTML页面和控制器中的值,我们应该使用ng-model
。
在您的情况下,它始终从控制器获取值,而不是通过HTML页面中的值绑定。
ng-value
与ng-model
<form ng-submit="myFunc()">
<input ng-model="sidebarname" type="text">
<input type="submit">
</form>
<p>{{myTxt}}</p>