我正在学习dart并尝试制作一个简单的webapp,因此应该可以创建用户。
但是当我尝试运行它时,会出现以下消息:
[SEVERE] web / main.dart上的build_web_compilers |入口点(已缓存): 无法找到某些来源的模块,这通常是由于 导入错误,包中缺少依赖项(或者可能是dev_dependency 需要移至实际依赖项)或构建失败(如果导入 生成的文件)。
请检查以下进口:
import 'package:Muellbot/app_component.template.dart' as ng;
来自Muellbot | web / main.template.dart,时间为9:1import 'package:Muellbot/app_component.template.dart' as ng;
来自Muellbot | web / main.dart,网址为2:1[SEVERE]在2.2秒后失败
这是我的文件:
main.dart
import 'package:angular/angular.dart';
import 'package:Muellbot/app_component.template.dart' as ng;
import 'package:angular_router/angular_router.dart';
import 'main.template.dart' as self;
@GenerateInjector(
routerProvidersHash,
)
final InjectorFactory injector = self.injector;
void main() {
runApp(ng.AppComponentNgFactory, createInjector: injector);
}
appComponent.dart
import 'package:angular/angular.dart';
import 'package:angular_router/angular_router.dart';
import 'src/routes.dart';
@Component(
selector: 'my-app',
styleUrls: ['app_component.css'],
templateUrl: 'app_component.html',
directives: [routerDirectives],
exports: [RoutePaths, Routes],
)
class AppComponent {
}
appComponent.html
<h1>Müllbot</h1>
<nav>
<a [routerLink]="RoutePaths.home.toUrl()"
[ routerLinkActive]="'active'">Home</a>
<a [routerLink]="RoutePaths.newUser.toUrl()"
[routerLinkActive]="'active'">Neuen Benutzer anlegen</a>
</nav>
<router-outlet [routes]="Routes.all"></router-outlet>
<img src="logo.png" width="50%">
routes.dart
import 'package:angular_router/angular_router.dart';
import 'route_paths.dart';
import 'home_component.template.dart' as home_template;
import 'create_new_user_component.template.dart' as new_user_template;
export 'route_paths.dart';
class Routes {
static final home = RouteDefinition(
routePath: RoutePaths.home,
component: home_template.HomeComponentNgFactory,
);
static final newUser = RouteDefinition(
routePath: RoutePaths.newUser,
component: new_user_template.NewUserComponentNgFactory,
);
static final all = <RouteDefinition>[
home,
newUser,
];
}
routhe_paths.dart
import 'package:angular_router/angular_router.dart';
class RoutePaths {
static final home = RoutePath(path: 'home');
static final newUser = RoutePath(path: 'newUser');
}
home_component.html
<h4>Hallo {{user.firstName}}</h4>
home_component.dart
import 'package:angular/angular.dart';
import 'user.dart';
@Component(
selector: 'home',
templateUrl: 'home_component.html'
)
class HomeComponent {
User user = new User('Axel', 'Foley', 'axel@sfoley.de');
}
create_new_user_component.html
<h3>Neuen Benutzer anlegen</h3>
<div>
<span *ngIf="!create" id="error">Fehler</span>
<span *ngIf="create" id="success">Benutzer angelegt</span>
<table>
<tr>
<td><label>Vorname:</label></td><td><input #firstName/></td>
<td><label>Nachname:</label></td><td><input #lastName/></td>
</tr><tr>
<td><label>Email:</label></td><td><input #email/></td>
</tr><tr>
<td><label>Passwort:</label></td><td><input #password/></td>
<td><label>Passwort wiederholen:</label></td><td><input #passwordRe/></td>
</tr><tr>
<td><button (click)="add(firstName.value, lastName.value, email.value, password.value)">Hinzufügen</button></td>
</tr>
</table>
</div>
create_new_user_component.dart
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart';
import 'package:angular/angular.dart';
@Component(
selector: 'new-user',
templateUrl: 'create_new_user_component.html'
)
class NewUserComponent {
bool create = false;
final Client _http;
static final _headers = {'Content-Type': 'application/json'};
final url = "http://localhost:4040/user/new";
Future<void> add(String firstName, String lastName, String email, String password) async {
try {
final response = await _http.post(url, headers: _headers, body: json.encode({'firstName': firstName, 'lastName': lastName, 'email': email, 'password': password}));
if (response.statusCode == 200) {
create = true;
}
} catch (e) {
throw new Exception(e);
}
}
}
答案 0 :(得分:0)
确定删除
<span *ngIf="!create" id="error">Fehler</span>
<span *ngIf="create" id="success">Benutzer angelegt</span>
有帮助。
但是现在我又遇到了另一个错误。服务器加载完毕,当我访问该页面时,它只会显示
Loading...
在控制台中,我收到消息
TypeError: e.message is undefined
答案 1 :(得分:0)
这个问题可以通过在您的 dir path
中完整导入包含您的项目 routes.dart
确保导入看起来像这样
import 'package:Muellbot/home_component.template.dart' as home_template;
import 'package:Muellbot/create_new_user_component.template.dart' as new_user_template;
不是这个
import 'home_component.template.dart' as home_template;
import 'create_new_user_component.template.dart' as new_user_template;