gpt4 book ai didi

angular - 将路由注入(inject)路由器导出会引发 'boolean expression must not be null' 错误

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

我刚开始使用 Angular Dart,我一直在使用路由教程:https://angulardart.dev/tutorial/toh-pt5作为引用,但每当将我的路由传递到路由器 socket 时,我的应用程序似乎就会爆炸

我尝试在不传递路由的情况下自行声明路由器 socket ,显然这没有产生任何错误,但也没有引入所需的组件。

route_paths.dart

class RoutePaths {
static final loginPath = RoutePath(path: 'login');
static final signUpPath = RoutePath(path: 'sign-up');
}


路线.dart
class Routes {
static final login = RouteDefinition(
routePath: RoutePaths.loginPath,
component: login_component.LoginComponentNgFactory
);

static final signUp = RouteDefinition(
routePath: RoutePaths.signUpPath,
component: sign_up_component.SignUpComponentNgFactory
);

static final all = <RouteDefinition> [
login,
signUp,
RouteDefinition.redirect(
path: '',
redirectTo: RoutePaths.loginPath.toUrl(),
)
];
}

app_component.dart
@Component(
selector: 'app-component',
templateUrl: 'app_component.html',
directives: [routerDirectives, NgIf],
exports: [RoutePaths, Routes],
)

class AppComponent {}


app_component.html

<h1>Hello there</h1>
<router-outlet [routes]="Routes.all"></router-outlet>

我希望我的登录路径在运行时可供用户使用,而不是在页面上得到“Hello there”,并且在控制台中出现以下错误:

EXCEPTION: Failed assertion: boolean expression must not be null STACKTRACE: dart:sdk_internal 11901:16 get isNotEmpty package:angular_router/src/directives/packages/angular_router/src/route_definition.dart 285:5 assertValid package:angular_router/src/directives/packages/angular_router/src/directives/router_outlet_directive.dart 82:14 set routes package:music_portal/packages/music_portal/app_component.template.dart 69:25 detectChangesInternal package:angular/src/bootstrap/packages/angular/src/core/linker/views/view.dart 58:7 detectCrash package:angular/src/bootstrap/packages/angular/src/core/linker/app_view.dart 377:7 detectChanges package:music_portal/packages/music_portal/app_component.template.dart 124:17 detectChangesInternal package:angular/src/bootstrap/packages/angular/src/core/linker/views/view.dart 58:7 detectCrash package:angular/src/bootstrap/packages/angular/src/core/linker/app_view.dart 377:7 detectChanges package:angular/src/bootstrap/packages/angular/src/core/change_detection/host.dart 128:13 [_runTickGuarded] package:angular/src/bootstrap/packages/angular/src/core/change_detection/host.dart 83:12 tick package:angular/src/bootstrap/packages/angular/src/core/application_ref.dart 107:5 [_loadedRootComponent] package:angular/src/bootstrap/packages/angular/src/core/application_ref.dart 95:7 package:angular/src/bootstrap/packages/angular/src/core/change_detection/host.dart 186:26 package:angular/src/core/change_detection/packages/angular/src/core/zone/ng_zone.dart 132:18 dart:sdk_internal 28349:14 run package:angular/src/core/change_detection/packages/angular/src/core/zone/ng_zone.dart 129:18 [_run] dart:sdk_internal 28555:14 run package:angular/src/core/change_detection/packages/angular/src/core/zone/ng_zone.dart 291:23 run package:angular/src/bootstrap/packages/angular/src/core/application_ref.dart 139:52 runInZone package:angular/src/bootstrap/packages/angular/src/core/change_detection/host.dart 184:5 run package:angular/src/bootstrap/packages/angular/src/core/application_ref.dart 69:23 bootstrap package:angular/src/bootstrap/packages/angular/src/bootstrap/run.dart 207:16 runApp main.dart 15:3 main webdev/src/serve/injected/client.js 11440:45 $0 webdev/src/serve/injected/client.js 3424:26 webdev/src/serve/injected/client.js 1188:72 webdev/src/serve/injected/client.js 4914:23 $2 webdev/src/serve/injected/client.js 4906:30 $1 webdev/src/serve/injected/client.js 5475:40 iB webdev/src/serve/injected/client.js 5477:30 dw webdev/src/serve/injected/client.js 5078:13 $0 webdev/src/serve/injected/client.js 1240:41 cJ webdev/src/serve/injected/client.js 4996:3 bz webdev/src/serve/injected/client.js 4932:3 ai webdev/src/serve/injected/client.js 4894:12 ai webdev/src/serve/injected/client.js 1179:20 bN webdev/src/serve/injected/client.js 3485:17 webdev/src/serve/injected/client.js 1188:72 webdev/src/serve/injected/client.js 4914:23 $2 webdev/src/serve/injected/client.js 4906:30 $1 webdev/src/serve/injected/client.js 5475:40 iB webdev/src/serve/injected/client.js 5477:30 dw webdev/src/serve/injected/client.js 5078:13 $0 webdev/src/serve/injected/client.js 1240:41 cJ webdev/src/serve/injected/client.js 5044:3 $0 webdev/src/serve/injected/client.js 1268:5 uK webdev/src/serve/injected/client.js 1270:7 uP webdev/src/serve/injected/client.js 4865:3 $1 webdev/src/serve/injected/client.js 441:17 vk webdev/src/serve/injected/client.js 449:51

最佳答案

事实证明,当使用 Firefox 开发 Angular Dart 应用程序时,它会在查找源映射文件时出现 404。

Source map error: request failed with status 404
Resource URL: http://localhost:8080/packages/build_web_compilers/src/dev_compiler/dart_sdk.js
Source Map URL: dart_sdk.js.map

Source map error: request failed with status 404
Resource URL: http://localhost:8080/webdev/src/serve/injected/client.js
Source Map URL: client.dart.js.map

老实说,我不知道为什么 Firefox 会阻止或找不到源映射文件,但切换到 Chrome 是解决该问题的即时解决方案。考虑到它们都是 Google 产品,我想这是有道理的。

编辑:可能相关的 github 问题: https://github.com/dart-lang/build/issues/1788

关于angular - 将路由注入(inject)路由器导出会引发 'boolean expression must not be null' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56886366/

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