2
我玩弄一個簡單的角度的例子,我還沒有弄清楚爲什麼我的ng重複指令不工作。下面的代碼片段僅僅是一個控制器,它向github提供了將用戶和回購數據返回的信息。角ng重複標記不工作
我可以確認我收到了用戶和回購數據,它的形狀和我期望的一樣,並且當onRepos()返回時,回收集合存在於$ scope中。我似乎無法得到使用ng-repeat渲染的repo名稱。我在控制檯中看不到任何錯誤,它只是不想工作。
我已經花了最後的30分鐘盯着這個,無法弄清楚。我錯過了什麼?
角1.3.15
app.js
(function(){
var app = angular.module('githubviewer',[]);
var MainController = function($scope, $http) {
var onUserComplete = function(response) {
$scope.user = response.data;
$http.get($scope.user.repos_url)
.then(onRepos, onError);
}
var onRepos = function(response) {
$scope.repos = response.data;
console.log($scope.repos[0].name);
}
var onError = function(response) {
$scope.error = response.data;
}
$scope.search = function(username) {
var url = "https://api.github.com/users/" + username;
$http.get(url).then(onUserComplete, onError);
}
$scope.message = "github viewer";
$scope.usename = "angular";
}
app.controller("MainController", ["$scope", "$http", MainController ]);
}());
的index.html
<!DOCTYPE HTML>
<html ng-app="githubviewer">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Angular JS - Getting Started</title>
<script src="angular.js" type="text/javascript" charset="utf-8"></script>
<script src="app.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div ng-controller="MainController">
<div> {{message}} </div>
<div> {{error}} </div>
<form name="searchUser" ng-submit="search(username)">
<input type="search" required placeholder="Username to find" ng-model="username">
<input type="submit" value="search">
</form>
<div>
<h2> Name : {{user.name}} </h2>
<img ng-src="{{user.avatar_url}}" title="{{user.name}}">
</div>
</div>
Repos: {{repos.length}}
<table>
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="repo in repos">
<td>{{ repo.name }}</td>
</tr>
</tbody>
</table>
</body>
</html>
它就在那裏。我不知道爲什麼沒有發生在我身上。 – nerraga