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

标签 javascript angularjs node.js ionic-framework mean-stack

我在通过 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/

相关文章:

javascript - 如何使用 LayoutView 显示 Collections?

javascript - 如何将字符串分割为两个或多个单词?

angularjs - for 循环和 Protractor 中的 if 问题

javascript - Angular ng-repeat 过滤器在数据检索之前运行

node.js - 如何将ReactJS应用程序(文件)编译成一个index.html文件?

javascript - 未捕获( promise )DOMException : Unable to decode audio data

javascript - ExtJS 6.2 无法将插件添加到内部网格 - TypeError : view is undefined

javascript - 将 Javascript 添加到队列上的 MSCRM 功能区工作台按钮

javascript - AngularJS 函数在 $compile 后不知道新的 dom 元素

javascript - ES 6 - 使用类