I would like to understand how I can solve this issue of the infinite digest Loop, should I write a conditional?
The objective is to use angular's 2-way data binding, but I need to modify the output to sort the letters randomly.
My HTML:
<div class="container-fluid phrase-container text-center">
<!-- == User Phrase Input == -->
<input type = "text" ng-model = "phrase.firstPhrase" placeholder="Please enter phrase"><br><br>
</div>
<div class="container-fluid anagram-container text-center">
<!-- == Final anagram == -->
Anagram: {{phrase.fullAnagram()}}
</div>
My javascript:
var app = angular.module("app", []);
app.controller('mainController', function($scope) {
$scope.main = {};
$scope.main.title = "AnagramJS";
// Refresh Page acts as reroll button
$scope.reloadRoute = function() {
$route.reload();
};
// Anagram Creation
$scope.phrase = {
firstPhrase: "",
fullAnagram: function() {
var finalPhrase;
finalPhrase = this.firstPhrase.split('').sort(function() {
return 0.5 - Math.random()
}).join('');
return finalPhrase
}
};
});