2014-09-25 102 views
0

我有几个问题关于$location.path(/helpmeunderstand)。我有一个login()方法和证书成功我想浏览$location.path(/login/:username),但它不显示登录的用户的名称,而只是显示,/login/:username

请注意我在$scope.function里面这样做,但不起作用。

$scope.isValidUser = function() { 
      gitHubApiFactory.getUserName($scope.gitUserName) 
       .success(function (user) { 
        $scope.gitUser = user; 
        $scope.loaded = true; 
        $location.path("/login/{{user.login}}"); 
        console.log(user); 

       }) 
       .error(function(data, status, headers, config) { 
        $scope.userNotFound = true; 
        $log.log(data.error + ' ' + status); 
       }); 

任何建议是值得欢迎的。

谢谢

+1

向我们展示一些代码.... – HaukurHaf 2014-09-25 10:21:19

+0

谢谢,现在的代码是在我的问题 – GeekOnGadgets 2014-09-25 10:27:48

回答

3

问题是您不能使用{{}}括号语法。它只适用于HTML模板和绑定。

试试这个:

$scope.isValidUser = function() { 
      gitHubApiFactory.getUserName($scope.gitUserName) 
       .success(function (user) { 
        $scope.gitUser = user; 
        $scope.loaded = true; 
        $location.path("/login/" + user.login); 
        console.log(user); 

       }) 
       .error(function(data, status, headers, config) { 
        $scope.userNotFound = true; 
        $log.log(data.error + ' ' + status); 
       }); 
+0

打我吧!这看起来很适合我。 – HockeyJ 2014-09-25 10:30:10

+0

谢谢你,先生:)救了我很多时间。对于angularjs很抱歉 – GeekOnGadgets 2014-09-25 10:34:11