简体   繁体   中英

AngularJs - $location.path not working

I have couple of questions regarding $location.path(/helpmeunderstand) . I have a login() method and ones the credentials are successful i want to navigate $location.path(/login/:username) , but it does not show the name of the user who is logged in instead it just shows, /login/:username .

Please note i am doing this inside of the $scope.function , but does not work.

$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);
                });

Any suggestion is welcome.

Thanks

The problem is that you cannot use the {{}} bracket syntax that way. It only works for HTML templates and bindings.

Try this:

$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);
                });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM