我正在尝试构建一个 Angular 应用程序,该应用程序根据用户名搜索 Github 用户并显示他们的存储库列表。 接下来,当用户单击任何存储库名称时,它应该显示未决问题和贡献者的列表。 这是笨蛋http://plnkr.co/edit/6ZzIkB7W1HgxQtuQjo5k?p=preview
please visit the plunk and make a test run on the app, i'm not able to explain my issue properly
我的repocontroller js。
(function(){
var app = angular.module('plunker');
app.controller('RepoCtrl', function($scope, $routeParams, $http, $log){
var username = $routeParams.username;
var reponame = $routeParams.reponame;
var onSuccess = function(response){
$scope.repo = response.data;
$http.get($scope.repo.contributors_url)
.then(onCollab , onError);
};
var onCollab = function(response){
$scope.contributors = response.data;
};
var onError = function(reason){
$scope.error = "Data Load Error";
};
//GET https://api.github.com/repos/:owner/:repo/contributors
$http.get('https://api.github.com/repos/' + 'username/' + 'reponame')
.then(onSuccess, onError);
});
}());
我在最后阶段遇到了麻烦,即当用户单击任何存储库名称而不是加载 repo.html 页面时,应用程序会再次重新加载主页。 你能帮我一下吗? :)
最佳答案
由于您网站的默认网址类似于 http://localhost/#!/main
你必须用 #!/来改变你的链接,就像 user.html
<a href="#!/repo/{{user.login}}/{{repo.name}}">{{repo.name}}</a>
和repo.html
<a href="#!/main">Back To Main</a>
<a href="#!/user/{{repo.owner.login}}">Back To {{repo.owner.login}}</a>
关于javascript - Angular 应用程序未将页面加载到 View 中并自行重新启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41929785/