Created
June 29, 2014 16:23
-
-
Save mondalaci/dc05b7eb3d06e6b0cdeb to your computer and use it in GitHub Desktop.
Angular Dart: Data binding doesn't work when manipulating the controller from the outside
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html ng-app> | |
<head> | |
<title>Angular.dart nested controllers</title> | |
</head> | |
<body> | |
<a href="#" id="open">open</a> | |
<div outer-controller ng-switch="outerCtrl.shouldShowInnerController"> | |
<input type="checkbox" ng-model="outerCtrl.shouldShowInnerController"> | |
<div inner-controller ng-switch-when="true"> | |
Your name: <input ng-model="innerCtrl.yourName"> | |
<br> | |
Hello {{innerCtrl.yourName}}! | |
</div> | |
</div> | |
<script type="application/dart"> | |
import "dart:html"; | |
import 'package:angular/angular.dart'; | |
import 'package:angular/application_factory.dart'; | |
OuterController outerController; | |
@Controller(selector:'[outer-controller]', publishAs:'outerCtrl') | |
class OuterController { | |
bool shouldShowInnerController; | |
static Scope scope; | |
OuterController(Scope _scope) { | |
scope = _scope; | |
outerController = this; | |
} | |
void showOuterController() { | |
shouldShowInnerController = true; | |
scope.apply(); | |
} | |
} | |
@Controller(selector:'[inner-controller]', publishAs:'innerCtrl') | |
class InnerController { | |
String yourName = 'defaultName'; | |
} | |
class MyAppModule extends Module { | |
MyAppModule() { | |
type(InnerController); | |
type(OuterController); | |
} | |
} | |
main() { | |
applicationFactory().addModule(new MyAppModule()).run(); | |
querySelector('#open').onClick.listen((Event event) { | |
outerController.showOuterController(); | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment