i am fiddling with angular and trying to understand when should i make a new controller or not. What i am trying to accomplish in angular is #1 randomizing a list when a user clicks the button. I can auto randomize, but not sure if on ng-click if that should require a new controller for the scope. and second thing i am trying to do is duplicate that list but when partner is clicked--it matches them with a random letter in the list. That involves appending another letter in the list to another. What I am wondering is, what if it is not even-what should happen to the extra letter? any suggestions. I think angular presents a cleaner way to solve problems then jquery.
var myApp = angular.module('myApp', []);
angular.module('myApp', [])
.controller('myCtrl', ['$scope', function($scope) {
$scope.list = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
$scope.random = function() {
return 0.5 - Math.random();
};
$scope.matchme = function() {
alert("this");
};
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<p ng-repeat="i in list">{{i}}</p>
<p ng-repeat="x in list2">{{i}}</p>
<button ng-click="random()">randomize</button>
<button ng-click="matchme()">partner</button>
</div>