gpt4 book ai didi

angularjs - 'indexOf'是不确定的?

转载 作者:行者123 更新时间:2023-12-03 08:05:31 26 4
gpt4 key购买 nike

我总是得到那个错误。因此,我很确定我的“$ scope.permissionExists = function()”出了问题

有任何想法吗?如果我错过发布相关代码-请告诉我

> TypeError: Cannot read property 'indexOf' of undefined
> at Scope.$scope.permissionExists(http://0.0.0.0:9000/scripts/controllers/signature.js:64:31)
> at Object.get (http://0.0.0.0:9000/bower_components/angular/angular.js:11064:21)
> at Scope.$digest (http://0.0.0.0:9000/bower_components/angular/angular.js:12775:40)
> at Scope.$apply (http://0.0.0.0:9000/bower_components/angular/angular.js:13050:24)
> at done (http://0.0.0.0:9000/bower_components/angular/angular.js:8525:45)
> at completeRequest (http://0.0.0.0:9000/bower_components/angular/angular.js:8739:7)
> at XMLHttpRequest.xhr.onreadystatechange (http://0.0.0.0:9000/bower_components/angular/angular.js:8678:11)

这是我的代码: JS
$scope.data = {
newCustomerSig: null,
newAccountSig: null,
user: null,
account: null,
permissions: null,
maxSms: 1
};
....
var getAccountPermission = function () {
// check only when authenticated (or refresh possible)
AccountPermissions.one().getList().then(
function (resultOk) {
var permission = resultOk.data;
$log.d("AccountPermissions ok: ", resultOk);
$scope.data.permissions = permission;
},
function (resultError) {
$log.d("Accountinfo error: ", resultError);
ErrorService.showApiError(resultError);
},
function (resultNotify) {
$log.d("Accountinfo notify:", resultNotify);
}
);
};

$scope.permissionExists = function () {
if (data.permissions.indexOf("sign_change_global") > -1) {
//In the array!
return true;
} else {
return false;
//Not in the array
}
};
....

“sign_change_global” <是数组中的值

HTML
....
<form name="formSignature" class="">
<div>
<i> Persönliche Signatur </i><br/>
<textarea id="persSignatur" name="persSignatur"
rows="5" cols="40"
use-sms-counter="data.smsCounter"
ng-model="data.newAccountSig"
ng-trim="false"
placeholder="{{data.user.signature}}">
</textarea>
<div>
{{data.newAccountSignewAccountSig}}
{{data.smsCounter.textLength}}
{{data.smsCounter.isUcs2}}
<div class="amount"
data-sms-counter="data.smsCounter"
data-sms-counter-content-list="[data.newAccountSig]"
data-max-messages="1">
</div>
{{data.smsCounter}}

</div>

</div>
....

最佳答案

在if语句的$scope.permissionExists = function ()中,您已经得到data.permissions,但是应该是$scope.data.permissions。它应该看起来像这样:-

$scope.permissionExists = function () {
if ($scope.data.permissions.indexOf("sign_change_global") > -1) {

我希望这有帮助。

关于angularjs - 'indexOf'是不确定的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25995860/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com