我想了解如何解决无限摘要循环的这个问题,我应该写一个条件吗?
目标是使用 Angular 的 2 路数据绑定,但我需要修改输出以随机排序字母。
我的 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>
我的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
}
};
});