I'm trying to implement functionality for checking multiple items in a list of checkboxes. I am using a Map to store the data and its selected/unselected state.
List<String> fruits = [
{'fruit': 'apple', 'selected': true},
{'fruit': 'banana', 'selected': true},
{'fruit': 'kiwi', 'selected': false}
];
The checkboxes display initially with the checked/unchecked status correctly rendered, but when I toggle a checkbox's checked status, the fruits
map does not update. How can I correctly create a two-way binding here?
Here is my .dart file:
import 'package:angular/angular.dart';
@NgDirective(
selector: '[my-controller]',
publishAs: 'ctrl'
)
class MyController {
List<String> fruits = [
{'fruit': 'apple', 'selected': true},
{'fruit': 'banana', 'selected': true},
{'fruit': 'kiwi', 'selected': false}
];
}
main() {
ngBootstrap(module: new Module()..type(MyController));
}
And here is the view markup:
<!DOCTYPE html>
<html ng-app>
<body>
<div my-controller>
<ul>
<li ng-repeat="item in ctrl.fruits">
{{item['fruit']}}
<input type="checkbox" ng-model="item['selected']" />
</li>
</ul>
</div>
<!-- THIS DOES NOT UPDATE WHEN THE CHECKBOXES ARE TOGGLED -->
{{ctrl.fruits}}
<script type="application/dart" src="main.dart"></script>
<script type="text/javascript" src="packages/browser/dart.js"></script>
</body>
</html>