view raw
Arkej Arkej - 8 months ago 36
AngularJS Question

Angular ng-repeat. Looping through the letters in string

I'va just started learning Angular and can't manage an issue with


I want to display every letter from input in a single
element. I tried many ways but nothing works.

Here's my code on codepen


Is this what you're looking for ?

Each letter will be printed in different span.

solution of Error: 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=""></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>
    <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>