我在控制器内部定义了一些相当大的二进制(200kb)数组。现在,我想将这些大型数组放在单独的文件中,并以某种方式包括它们或将其保存在我的控制器中。
有没有一种优雅的方法可以做到这一点?我可以将阵列放在不同的服务中,然后从服务中获取阵列吗?
只是为了详细说明@hansmaad的答案并提供演示
的HTML
<div ng-app="myApp" ng-controller="myController">
<div ng-repeat="item in bigArray">
<h1>{{item.name}}</h1>
</div>
</div>
的JavaScript
var app = angular.module("myApp", []);
//In another file
app.constant("BigArray", [
{
name: "Item 1"
},
{
name: "Item 2"
},
{
name: "Item 3"
}
]);
//In another file end
app.controller("myController", ["$scope", "BigArray", function($scope, BigArray){
$scope.bigArray = BigArray;
}]);
更新
的HTML
<div ng-app="myApp" ng-controller="myController">
<div ng-repeat="item in bigArray">
<h1>{{item}}</h1>
</div>
</div>
的JavaScript
var app = angular.module("myApp", []);
//In another file
app.constant("BigArray", new Uint8Array([0x10, 0x20, 0x30]));
//In another file end
app.controller("myController", ["$scope", "BigArray", function($scope, BigArray){
$scope.bigArray = BigArray;
}]);
更新了JSFiddle
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句