gpt4 book ai didi

angularjs - Angular ng 重复。循环遍历字符串中的字母

转载 作者:行者123 更新时间:2023-12-02 23:42:20 25 4
gpt4 key购买 nike

我刚刚开始学习 Angular,无法解决 ng-repeat 的问题。

我想在单个 span 元素中显示输入的每个字母。我尝试了很多方法但没有任何效果。

Here's my code on codepen

最佳答案

这是您要找的吗?

每个字母将以不同的跨度打印。

solution 错误:ngRepeat:dupes

var app = angular.module('myApp', []);

app.controller('myCtrl', function($scope) {

});
.center-block {
float: none;
}

input {
margin: 20px;
}

span:hover {
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl" class="container">

<div class="col-sm-10 center-block text-center">

<input type="text" class="form-control" placeholder="Type to search..." ng-model="word" />

<div ng-repeat="letter in word.split('') track by $index">
<span> {{ letter }} </span>
</div>
<br/><br/> If you want to split the word by line <br/><br/>
<div ng-repeat="letter in word.split(' ') track by $index">
<span> {{ letter }} </span>
</div>
</div>
</div>

关于angularjs - Angular ng 重复。循环遍历字符串中的字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39512576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com