Angularjs完成数字能量数组任意排列的方式

//必须导进angular.js库文档 script type="text/javascript" src="../angular-1.5.5/angular-1.5.5/angular.js" /script script type="text/javascript" var app = angular.module("myApp", []); var arr1 = [1, 2, 3, 7, 4, 9, 5, 6]; app.service("sortService", function() { this.arr = [1, 2, 3, 7, 4, 9, 5, 6]; this.t; this.mySort = function() { //alert("haha"); for(var i = 0; i this.arr.length; i++) { var rand = parseInt(Math.random() * this.arr.length); this.t = this.arr[rand]; this.arr[rand] = this.arr[i]; this.arr[i] = this.t; app.controller("myCtrl", function($scope, sortService) { $scope.arr = arr1; $scope.newArr = sortService.arr; $scope.mySort2 = sortService.mySort; /*$scope.mySort2 = function(){ sortService.mySort(); /script /head body ng-app="myApp" ng-controller="myCtrl" {{newArr}} br button ng-click="mySort2()" 点一下任意排列 /button br {{arr}} !--{{arr}} button ng-click="mySort2()" 点一下任意排列 /button {{newArr}}-- /body /html

Angularjs 数组随机排序

之上这篇Angularjs完成数字能量数组任意排列的方式便是网编共享给大伙儿的所有內容了,期待能给大伙儿一个参照,也期待大伙儿多多的适用诺心互联网。



扫描二维码分享到微信