gpt4 book ai didi

javascript - Angular 警告 "Form submission canceled because the form is not connected"

转载 作者:太空宇宙 更新时间:2023-11-04 15:54:52 29 4
gpt4 key购买 nike

html代码:

 <form action="{{url}}"> 
<input type="submit" class="btn btn-info" ng-
click="goToProdPage()" value="Resume">
</form>

Angular 代码:

    $scope.goToProdPage = function(){
if(id){
$scope.url = "#/"+id+"/cpq";
console.log("done "+id);
$state.go("cpq");
}
}

请忽略 ID,因为我只放了一半代码。我已经使用了 $(document.body).append(form);它解决了这个问题但是现在添加它之后它在控制台上显示如下错误

angular.js:14362 ReferenceError: form is not defined at b.$scope.findUser.$scope.goToProdPage (login.js:44) at fn (eval at compile (angular.js:15197), :4:156) at e (angular.js:26808) at b.$eval (angular.js:18017) at b.$apply (angular.js:18117) at HTMLInputElement. (angular.js:26813) at dg (angular.js:3617) at HTMLInputElement.d (angular.js:3605)

最佳答案

不能 100% 确定您在这里要做什么。但我的意见是,您应该使用更具有 Angular 风格的方式来处理表单...

<form ng-submit="mySubmit()">
<input type="submit" value="Send form">
</form>

现在您可以在 Controller 中编写一个函数来处理表单的提交。

this.mySubmit = mySubmit;

function mySubmit() {
// Check here if the url exists
// ...or what to do when submitting the form...
// this.goToProdPage();
}

更详细的示例或额外信息可以帮助我更好地理解问题:-)

关于javascript - Angular 警告 "Form submission canceled because the form is not connected",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46618455/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com