Angular/Nodejs 中的无引用函数错误

Unrefrenced function Error in Angular/Nodejs

本文关键字:引用 函数 错误 Nodejs Angular      更新时间:2023-09-26

我遇到通过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>