Angular TypeError:无法读取属性';下一个';指未定义的行为主体

Angular TypeError:无法读取属性';下一个';指未定义的行为主体,angular,angular9,Angular,Angular9,我的代码在运行时和执行console.logs时都正常工作。日志显示,isqrcodeshow$未定义 我收到错误TypeError:无法读取未定义的属性“next” TypeError: Cannot read property 'next' of undefined at <Jasmine> at SafeSubscriber.setQrShown [as _next] (http://localhost:9876/_karma_webpack_/src/app/

我的代码在运行时和执行console.logs时都正常工作。日志显示,
isqrcodeshow$
未定义

我收到错误
TypeError:无法读取未定义的属性“next”

TypeError: Cannot read property 'next' of undefined
    at <Jasmine>
    at SafeSubscriber.setQrShown [as _next] (http://localhost:9876/_karma_webpack_/src/app/modules/review-sign/services/qr-code/qr-code.service.ts:24:25)
    at SafeSubscriber.__tryOrUnsub (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm2015/internal/Subscriber.js:183:1)
    at SafeSubscriber.next (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm2015/internal/Subscriber.js:122:1)
    at Subscriber._next (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm2015/internal/Subscriber.js:72:1)
    at Subscriber.next (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm2015/internal/Subscriber.js:49:1)
    at MapSubscriber._next (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm2015/internal/operators/map.js:35:1)
    at MapSubscriber.next (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm2015/internal/Subscriber.js:49:1)
    at Observable._subscribe (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm2015/internal/util/subscribeToArray.js:3:1)
    at Observable._trySubscribe (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm2015/internal/Observable.js:42:1)
    at Observable.subscribe (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm2015/internal/Observable.js:28:1)
这是我使用BehaviorSubject
服务添加两个测试的时候。isqrcodeShowed$

  • 当给定国家/地区不在列表中时,IsqrCodeShowed$应为false
  • 当给定国家/地区在列表中时,IsqrCodeShowed$应为真

我还使用ff命令
ng test测试它——include file path/file.spec.ts

setqrshow
不是一个箭头函数,这里

//...
    .subscribe(this.setQrShown);
上下文丢失。您可以更详细一些:

    .subscribe(value => this.setQrShown(value));
或将
setqr设置为箭头函数:

setQrShown = (country: string): void => {

我的错误,看起来像是一个
词法范围界定问题。谢谢你的回答:)
    .subscribe(value => this.setQrShown(value));
setQrShown = (country: string): void => {