2017-01-07 23 views
0

我認爲我做的一切都很好,但仍然收到此錯誤。任何人請引導我通過。我有我的JavaScript文件中的兩個功能,第一是myfunction的和第二是goAndFind但首先是在NG-變化工作正常,但兩者功能不工作的onclick上的按鈕:Uncaught ReferenceError:goAndFind未定義在HTMLInputElement.onclick

這是我的JavaScript文件

/// <reference path="angular.min.js"/> 
 
// Initialize Firebase 
 
var config = { 
 
    apiKey: "AIzaSyDTTDn-oR0XadcSwllwUkukrw86eH2Ch0g", 
 
    authDomain: "mvprecovery.firebaseapp.com", 
 
    databaseURL: "https://mvprecovery.firebaseio.com", 
 
    storageBucket: "mvprecovery.appspot.com", 
 
    messagingSenderId: "119468568560" 
 
}; 
 
firebase.initializeApp(config); 
 
var myapp = angular 
 
        .module("mymodule", ['firebase']) 
 
        .controller("mycontroller", function ($scope , $firebaseObject) { 
 
         
 
         $scope.selectState; 
 
         $scope.findTreatment = findTreatment; 
 
         $scope.selectState = selectState; 
 
         $scope.selectedInsurance = selectedInsurance; 
 

 
         $scope.goAndFind = function writeUserData() { 
 
             firebase.database().ref('tempdata/' + userId).set({ 
 
              insurance: $scope.selectedInsurance, 
 
              state: $scope.selectState, 
 
              treatment: $scope.findTreatment 
 
          }); 
 
         }; 
 

 
         $scope.myfunction = function() { 
 
          if ($scope.selectState == "Pennsylvania") { 
 
           $scope.insurance = [ 
 
                { name: "Ford Mustang" }, 
 
                { name: "Fiat 500" }, 
 
                { name: "Volvo XC90" } 
 
           ]; 
 
          } else if ($scope.selectState == "new-jersey") { 
 
           $scope.insurance = [ 
 
               { name: "lahore" }, 
 
               { name: "kamalia" }, 
 
               { name: "bingokml" } 
 
           ]; 
 
          } 
 
         }; 
 

 
});

,這是被點擊我的按鈕代碼

<input type="button" class="btn-success" id="findTreatment" value="Find Treatment" ng-disabled="myform.$invalid && myform.insurancefield.$invalid" onclick="goAndFind()" />

回答

0

使用ng-click代替onclick,因爲您使用的是角度。

<input type="button" class="btn-success" id="findTreatment" value="Find Treatment" ng-disabled="myform.$invalid && myform.insurancefield.$invalid" ng-click="goAndFind()" /> 

另外,還要考慮給你的功能(例如的,而不是setInsurancemyfunction)更清晰的名字。這會在稍後幫助你。

相關問題