gpt4 book ai didi

javascript - Angular/Nodejs 中未引用的函数错误

转载 作者:太空宇宙 更新时间:2023-11-04 03:30:46 24 4
gpt4 key购买 nike

我在通过 onclick() 将函数附加到按钮时遇到问题。我使用 UI 路由将 Controller 附加到带有 ionic 标签的 html 页面。这是代码片段--

app.js

var havyakkaMaduve  = angular.module('havyakka_maduve',     ['ionic','ngStorage','ngCordova','ngCordovaOauth'])

havyakkaMaduve.config(function($stateProvider, $urlRouterProvider) {

$stateProvider

// setup an abstract state for the tabs directive
.state('home', {
url: '/',
templateUrl: 'homePage.html',
controller: 'LoginController'
})
.state('registration', {
url:'/reg',
templateUrl:'templates/registration.html',
controller:'UserDetailsController'
});

// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise("/reg");

});

havyakkaMaduve.controller("UserDetailsController",["$scope","$http", function($scope,$http) {
console.log("Inside userDetails Controller");
$scope.submitDetails = function () {
console.log("Submitting details");
$http.get("/test").success(function(response){
console.log("Test success");
});
};


}]);

注册.html

<ion-pane>
<ion-content class="padding">
<div class="reg_list">
<label class="item item-input">
<span class="input-label">Full Name</span>
<input type="text" required>
</label>
<label class="item item-input">
<span class="input-label">Mane</span>
<input type="text" required>
</label>
<label class="item item-input">
<span class="input-label">Gotra</span>
<input type="text" required>
</label>
<label class="item item-input">
<span class="input-label">Date</span>
<input type="date" required>
</label>
<label class="item item-input">
<span class="input-label">Education</span>
<input type="text" required>
</label>
<label class="item item-input">
<span class="input-label">Occupation</span>
<input type="text" required>
</label>
<label class="item item-input">
<span class="input-label">Father's Name</span>
<input type="text" required>
</label>
<label class="item item-input">
<span class="input-label">Mother's Name</span>
<input type="text" required>
</label>
<label class="item item-input">
<span class="input-label">Current Location</span>
<input type="text" required>
</label>
<label class="item item-input">
<span class="input-label">Upload Image</span>
<input type="file" required>
</label>
<label class="item item-input">
<span class="input-label">Digital Identity</span>
<input type="url" required>
</label>
<label class="item item-input">
<span class="input-label">About Me</span>
<input type="text">
</label>
</div>
<button class="button button-block button-positive" onclick="submitDetails">Submit</button>
<div>
</div>

有人请告诉我哪里出了问题,因为我在这里没有看到任何问题,但我收到“ReferenceError:submitDetails 未定义”。单击“提交”按钮时我看到了问题。谢谢。

最佳答案

您必须使用 ng-click 而不是 onclick,并且应使用括号调用该函数:

<button class="button button-block button-positive" ng-click="submitDetails()">Submit</button>

关于javascript - Angular/Nodejs 中未引用的函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38273417/

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