AngularJS: Shows reference error : goToFormDashboard not defined in scope

AngularJS: Shows reference error : goToFormDashboard not defined in scope

我试图在 onchange 事件上调用一个函数,但每次该函数都会出现引用错误,我的代码是这样的:

        <label class="item item-input item-select" ng-controller="manageTeam">
            <div class="input-label">
                Select Form
            </div>
            <select onchange="goToFormDashboard($(this).children(':selected').val())" ng-model="Formname" ng-options="f.Formname for f in forms track by f.Formid"></select>
        </label>

我的控制器是这样的:

.controller('manageTeam', function($scope, $ionicLoading, $http, $timeout, $rootScope, $state) {
    $scope.goToFormDashboard = function (formId) {
        $ionicLoading.show({template: 'Loading'});
        $timeout(function () {
            $ionicLoading.hide();
        }, 1500);
        var formID = formId;
        $scope.form.length = 0;
        .....

是不是少了什么?

在JavaScript中"this"表示调用实际方法的函数。示例:

var myObject = function();
myObject.prototype.testvar = "hello world";
myObject.prototype.test = function(){ 
  return this.testvar;
}
var obj = new myObject();
console.log(obj.test());

这会在您的 chrome 控制台中显示 "hello world"。您不需要将下拉列表的值传递给提交处理程序。看看

Angular JS: Pass a form's select option value as parameter on ng-submit="doStuff()"

这正是您要搜索的内容

你需要使用ng-change指令而不需要使用jquery在这里你可以得到ng-model里面的值,Formname包含你可以传递表单的整个对象id 仅通过执行 Formname.FormidgoToFormDashboard 方法。

标记

<select ng-change="goToFormDashboard(Formname.Formid)" ng-model="Formname" 
ng-options="f.Formname for f in forms track by f.Formid"></select>