未捕获的ReferenceError:未在HTMLInputElement.onclick中定义goAndFind

时间:2017-01-07 00:38:24

标签: html css angular-ui-bootstrap

我想我做的一切都很好,但我仍然得到这个错误。任何人请指导我。我在我的javascript文件中有两个函数,第一个是myfunction,第二个是goAndFind,但是第一个在ng-change上工作正常,但两个函数都没有工作点击按钮:

这是我的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()" />

1 个答案:

答案 0 :(得分:0)

使用ng-click代替onclick,因为你正在使用angular。

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

另外,请考虑为您的函数指定一个更清晰的名称(例如,setInsurance而不是myfunction)。这将在以后帮助你。