在Controller中调用该函数会引发未定义的错误

时间:2018-04-19 01:15:51

标签: javascript angularjs controller

我是Angular Java脚本的新手,我正在尝试调用一个函数并在Controller中使用返回的值,如下所示

    $scope.findprojectBarcode = function (p) {
        var prjBarCode = "";
        var i = 0;
        for (i = 0; i < $rootScope.projectList.value.length; i++) {
            if ($rootScope.projectList.value[i].Name === p) {
                console.log($rootScope.projectList.value[i].Name);
                return $rootScope.projectList.value[i].Barcode;
            }
        }
        return prjBarCode;
    };

   $scope.postRequest = function () {
        var prjCode = findprojectBarcode($scope.request.projectSelectedBarcode);
        var data = {
            "PROJECT@odata.bind": ["/PROJECT('" + prjCode + "')"]
        };

但是当尝试调试它时会抛出findprojectBarcode is not defined之类的错误。我不确定我是否在这里遗漏了一些东西。

html代码是

        <div hidden id="projectSelected">
            <label style="font-size: medium">Project *</label>
            <select name="projectSelected" id="projectSelectedId" class="form-control" ng-model="request.projectSelectedBarcode" required>
              <option ng-repeat="prj in projectList" value="{{prj.Name}}">{{ prj.Name }}</option>
            </select>
            <div style="color:maroon" ng-messages="getServiceReuqestForm.projectSelected.$error"
                 ng-if="getServiceReuqestForm.projectSelected.$touched">
                <div ng-message="required">This field is required</div>
            </div>
        </div>

1 个答案:

答案 0 :(得分:0)

试试这个

var prjCode = $scope.findprojectBarcode($scope.request.projectSelectedBarcode);