出于某种原因,当我的控制器的成员变量被更改(链接到我的HTML)时,浏览器会重新渲染以显示新变量,直到我在同一页面上输入一个输入框。我是预期的
{{SignInCtrl.userLoggedIn}}
在更改bool userLoggedIn
时自动更新。
控制器
import 'package:angular/angular.dart';
import 'package:js/js.dart' as js;
import 'dart:html'; //for window.console
@NgController(
selector: '[signin-controller]',
publishAs: 'SignInCtrl')
class SignInController {
bool userLoggedIn = false;
HTML
<!DOCTYPE html><html ng-app>
<head><meta charset='UTF-8'>
<script src='//cdnjs.cloudflare.com/ajax/libs/modernizr/2.7.1/modernizr.dev.js'></script>
<link rel='stylesheet prefetch' href='//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css'>
<style>.ng-hide{
display: none !important;
}
.ng-show {
}
#auth {
border: none;
}
@media screen and (max-width: 740px) {
#auth button {
width: 100%;
}
}</style></head><body>
<main ng-cloak signin-controller>
<nav class="navbar navbar-default" role="navigation" ng-controller="SignInCtrl">
<span>
Is user logged in: {{SignInCtrl.userLoggedIn}}
</span>
</nav>
</main>
<script type="text/javascript" src="packages/browser/dart.js"></script>
<script src="packages/browser/interop.js"></script>
<script src='https://cdn.firebase.com/v0/firebase-simple-login.js'></script>
<script src="https://cdn.firebase.com/v0/firebase.js"></script>
<script src="packages/shadow_dom/shadow_dom.min.js"></script>
<script type="application/dart" src="main.dart"></script>
</body>
</html>
main.dart
import 'package:angular/angular.dart';
@MirrorsUsed(override: '*') //used to make js output files smaller
import 'dart:mirrors';
import 'package:my_app/app_module.dart';
void main() {
ngBootstrap(module: new AppModule());
}