String を受け取り、それを s のリストに変換するコンポーネントを作成しています<span>
。それぞれ<span>
が String 文字を取得し、ランダムな色が割り当てられます。
コンポーネントの呼び出しは次のようになります。
<span ng-repeat="char in ctrl.chars" style="color: {{ctrl.randomColor}};">
{{char}}
</span>
コンポーネントの定義は次のようになります。
import 'package:angular/angular.dart';
import 'dart:math';
@NgComponent(
selector: 'tokens',
templateUrl: './component.html',
cssUrl: './component.css',
publishAs: 'ctrl',
map: const {
'text' : '@text',
}
)
class TokensComponent {
String text;
List<String> get chars => text.split('');
String get randomColor {
var colors = ['red', 'green', 'yellow', 'blue'];
return colors[new Random().nextInt(colors.length)];
}
}
これは機能しますが、エラーが発生します。
5 $digest() iterations reached. Aborting!
Watchers fired in the last 3 iterations:
...
私が定義しているゲッターを超えて、ここで何が監視されているのかは私には明らかではありません。getter にを含むコードを残し、Random
ハードコーディングされた文字列を返すだけで、エラー メッセージは表示されなくなります。
ここで何が間違っているのですか?