Angular/Nodejs 中的无引用函数错误
Unrefrenced function Error in Angular/Nodejs
我遇到通过onclick()附加到按钮的函数的问题。我已经使用 UI 路由将控制器附加到带有离子标签的 html 页面。这是代码片段——
应用.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>
有人请告诉我哪里出错了,因为我在这里没有看到任何问题,但我得到"参考错误:提交详细信息未定义"。单击"提交"按钮时,我看到问题。谢谢。
你必须使用 ng-click 而不是 onclick,并且应该用括号调用该函数:
<button class="button button-block button-positive" ng-click="submitDetails()">Submit</button>
相关文章:
- 这在 Object 方法中不引用对象,而是引用函数绑定到的标记
- Javascript在引用函数到变量时等于这个
- 引用函数数组中的另一个函数
- window.load上单独的javascript文件中的引用函数
- 如何引用函数
- JavaScript:函数字典:函数可以从其字典中引用函数
- 未捕获的引用函数上的错误
- 从不同的.JS文件中引用函数中的数组
- 动态引用函数时的Javascript变量范围
- 函数作为对象中的属性:引用函数内部的其他属性
- 在Javascript中,如何引用函数范围内的变量,该变量来自在该函数中调用但在其他地方定义的函数
- 在IIFE中引用函数
- 如何从函数自己的实现中引用函数
- 是否可以从HTML文件中的特定脚本标签引用函数或对象?
- 在函数中引用函数的属性
- 在'class'在同一个类中引用函数不起作用
- 从JavaScript对象内的函数中引用函数
- JavaScript函数被事件监听器多次调用,即使我引用函数
- 在angularjs中的$scope成员函数中引用函数中的变量
- 如何用文档引用函数