0
嗨我是新的angularjs我想知道是否有可能發送的東西已經加載在視圖從JSON回控制器。 我想要做的是將字母發回控制器,並創建一種方式來迭代它們與intervale然後改變每個控制器的樣式現在我卡住,因爲我無法得到ng-module = 「單一的」 回間隔控制器名稱如何從angularjs中的json更改控制器與視圖
這裏是視圖
<!DOCTYPE html>
<html lang="en-us" ng-app="App">
<body ng-controller="mainController" ng-click="textArea = textArea + 1">
<div ng-controller="clickController">
<div class="container">
<div ng-controller="intervalController">
<ul class="general_button"ng-repeat="letter in language[0].rows">
<button type="button" ng-model="single += single" class="btn btn-info" ng-repeat="single in letter">
{{single}}
</button>
</ul>
<div >
<h1 ng-mousemove="textArea = textArea + 1">Mouse over me!</h1>
<label for="inputlg">input-lg</label>
<input class="form-control input-lg" id="inputlg" type="text" value="{{ textArea }}">
</div>
</div>
</div>
</div>
</body>
</html>
這裏是控制器
var App = angular.module('App', []);
var theLanguage = 'english';
App.controller('mainController', function($scope, $http,$log) {
$http.get(theLanguage + '.json')
.then(function(res){
$scope.language = res.data;
});
$log.debug('Hello Debug!');
});
App.controller('intervalController', function($scope, $log) {
this.$log = $log;
var name = $scope.single;
$log.log(name);
$log.log('Hello World!');
});
App.controller('clickController', function($scope) {
});
,這裏是將JSON
[{
"rows":[[
"a",
"e",
"u",
"i",
"o",
"y"
],
[
"b",
"c",
"d",
"f",
"g"
],
[
"h",
"i",
"j",
"k",
"l"
],
[
"m",
"n",
"p",
"q",
"r"
],
[
"s",
"t",
"v",
"w",
"x z"
]
]}]
在此先感謝您的幫助,有關如何更好地完成此任務的任何建議也將不勝感激。
我嘗試添加angular.forEach($ scope.letter,功能(單){$ 日誌。 log(single); });但它似乎沒有工作 –