按照本教程中的步骤进行操作:
https://codelabs.developers.google.com/codelabs/angulardart-firebase-web-app/#9
当app_component.dart看起来如下时,一切正常:
import 'package:angular/angular.dart';
import 'package:angular_components/angular_components.dart';
import 'package:firebase/firebase.dart';
import 'src/todo_list/todo_list_component.dart';
// AngularDart info: https://webdev.dartlang.org/angular
// Components info: https://webdev.dartlang.org/components
@Component(
selector: 'my-app',
styleUrls: const ['app_component.css'],
templateUrl: 'app_component.html',
directives: const [materialDirectives, TodoListComponent],
providers: const [materialProviders],
)
class AppComponent implements OnInit{
// Nothing here yet. All logic is in TodoListComponent.
int count = 0;
DatabaseReference ref;
dislike() {
print("dislike");
}
like() {
print("like");
}
@override
ngOnInit() {
initializeApp(
apiKey: "AIzaSyAH7S_gsce9RtNI8w0z7doiP3ugVJM8ZbI",
authDomain: "angulardart-firebase-io-2017.firebaseapp.com",
databaseURL: "https://angulardart-firebase-io-2017.firebaseio.com",
storageBucket: "angulardart-firebase-io-2017.appspot.com");
ref = database().ref('counter');
ref.onValue.listen((e) {
count = e.snapshot.val();
});
}
}
,app_component.html如下所示
{{count}}
但是,当我将app_component.html更改为以下内容时:
<button (click)="dislike()")>Dislike</button>
<span>{{count}}</span>
<button (click)="like()">Like</button>
然后运行
pub serve
在浏览器中打开localhost:8080,我在控制台中收到以下错误:
html_dart2js.dart:3558 EXCEPTION: Error in package:holygrail/app_component.html:2:0
STACKTRACE:
EXCEPTION: Error in package:holygrail/app_component.html:2:0
ORIGINAL EXCEPTION: InvalidCharacterError: Failed to execute 'setAttribute' on 'Element': ')' is not a valid attribute name.
ORIGINAL STACKTRACE:
Error: Failed to execute 'setAttribute' on 'Element': ')' is not a valid attribute name.
at ViewAppComponent0.build$0 (http://localhost:8080/main.dart.js:58614:12)
at ViewAppComponent0.dart.AppView.create$2 (http://localhost:8080/main.dart.js:21820:21)
at ViewAppComponent0.create$2 (http://localhost:8080/main.dart.js:23171:21)
at _ViewAppComponentHost0.build$0 (http://localhost:8080/main.dart.js:58840:50)
at _ViewAppComponentHost0.dart.AppView.createHostView$2 (http://localhost:8080/main.dart.js:21826:21)
at _ViewAppComponentHost0.createHostView$2 (http://localhost:8080/main.dart.js:23184:21)
at ComponentFactory.create$2 (http://localhost:8080/main.dart.js:22161:53)
at ApplicationRefImpl_bootstrap_closure.call$0 (http://localhost:8080/main.dart.js:20852:22)
at ApplicationRefImpl_run_closure.dart.ApplicationRefImpl_run_closure.call$0 (http://localhost:8080/main.dart.js:20816:34)
at StaticClosure.dart._rootRun (http://localhost:8080/main.dart.js:6921:18)
ERROR CONTEXT:
Instance of 'DebugContext'
at Object.wrapException (http://localhost:8080/main.dart.js:4019:17)
at ViewAppComponent0._rethrowWithContext$3$stopChangeDetection (http://localhost:8080/main.dart.js:23341:21)
at ViewAppComponent0._rethrowWithContext$2 (http://localhost:8080/main.dart.js:23345:21)
at ViewAppComponent0.create$2 (http://localhost:8080/main.dart.js:23176:16)
at _ViewAppComponentHost0.build$0 (http://localhost:8080/main.dart.js:58840:50)
at _ViewAppComponentHost0.dart.AppView.createHostView$2 (http://localhost:8080/main.dart.js:21826:21)
at _ViewAppComponentHost0.createHostView$2 (http://localhost:8080/main.dart.js:23184:21)
at ComponentFactory.create$2 (http://localhost:8080/main.dart.js:22161:53)
at ApplicationRefImpl_bootstrap_closure.call$0 (http://localhost:8080/main.dart.js:20852:22)
at ApplicationRefImpl_run_closure.dart.ApplicationRefImpl_run_closure.call$0 (http://localhost:8080/main.dart.js:20816:34)
ORIGINAL EXCEPTION: InvalidCharacterError: Failed to execute 'setAttribute' on 'Element': ')' is not a valid attribute name.
ORIGINAL STACKTRACE:
Error: Failed to execute 'setAttribute' on 'Element': ')' is not a valid attribute name.
at ViewAppComponent0.build$0 (http://localhost:8080/main.dart.js:58614:12)
at ViewAppComponent0.dart.AppView.create$2 (http://localhost:8080/main.dart.js:21820:21)
at ViewAppComponent0.create$2 (http://localhost:8080/main.dart.js:23171:21)
at _ViewAppComponentHost0.build$0 (http://localhost:8080/main.dart.js:58840:50)
at _ViewAppComponentHost0.dart.AppView.createHostView$2 (http://localhost:8080/main.dart.js:21826:21)
at _ViewAppComponentHost0.createHostView$2 (http://localhost:8080/main.dart.js:23184:21)
at ComponentFactory.create$2 (http://localhost:8080/main.dart.js:22161:53)
at ApplicationRefImpl_bootstrap_closure.call$0 (http://localhost:8080/main.dart.js:20852:22)
at ApplicationRefImpl_run_closure.dart.ApplicationRefImpl_run_closure.call$0 (http://localhost:8080/main.dart.js:20816:34)
at StaticClosure.dart._rootRun (http://localhost:8080/main.dart.js:6921:18)
ERROR CONTEXT:
答案 0 :(得分:2)
还有一个额外的)在结束标记之前是不允许的。错误消息不是很好。解析器正在改变,并将提供更好的错误消息,该消息刚刚着陆并将在下一版本的角度中。
消息将更改为:
[SEVERE]: Error running TemplateGenerator for lib/buttons.dart.
Template parse errors:
line 1, column 16 of ButtonsExampleComponent:
Expected whitespace before a new decorator
<section class="margin")>
^^^^^^^^