简体   繁体   English

MEAN.js-推送功能后如何重定向

[英]MEAN.js - How to redirect after Push function

Im new to MEAN.js and im trying to figure out how to redirect a user after posting a comment to an article. 我是MEAN.js的新手,我试图找出在发表评论后如何重定向用户。

The function called is addComment and adds the comment fine after pressing submit. 调用的函数为addComment,并在按下提交后添加注释。 What i need to know is how to redirect similar to the way it redirects after posting an article. 我需要知道的是如何重定向,类似于发布文章后的重定向方式。

addComment() Pushing to a nested Array addComment()推送到嵌套数组

$scope.addComment = function () {

        var article = $scope.article;

        $scope.article.comment.push({details: this.details, created: Date.now(), user: user._id});
        $scope.update(false);
        this.details = '';
        console.log(article._id);
        $location.path('articles/' + article._id);
        console.log(article._id);

    };

I need to use the $location.path('articles/' + article._id); 我需要使用$ location.path('articles /'+ article._id); properly if the push was successful. 如果推送成功,则正确。

Thanks in advance. 提前致谢。

Try injecting $window and run a lower level location api with $window.location.href = 'path'; 尝试注入$window并使用$window.location.href = 'path';运行较低级别的位置api $window.location.href = 'path';

also it may matter that you want to keep your data in sync so try $location.path('/someNewPath').replace(); 同样,保持数据同步也可能很重要,因此请尝试$location.path('/someNewPath').replace();

also take a look at your $locationProvider service settings 还看看您的$locationProvider服务设置

$location service configuration To configure the $location service, retrieve the $locationProvider and set the parameters as follows: $ location服务配置要配置$ location服务,请检索$ locationProvider并按如下所示设置参数:

html5Mode(mode): {boolean|Object} true or enabled:true - see HTML5 mode false or enabled:false - see Hashbang mode requireBase:true - see Relative links default: enabled:false html5Mode(mode):{boolean | Object} true或enabled:true-请参见HTML5模式false或enabled:false-请参见Hashbang模式requireBase:true-请参见相对链接默认值:enabled:false

hashPrefix(prefix): {string} prefix used for Hashbang URLs (used in Hashbang mode or in legacy browser in Html5 mode) default: "" hashPrefix(prefix):用于Hashbang URL的{string}前缀(在Hashbang模式或Html5模式下的旧版浏览器中使用)默认:“”

More information about the $location service in the Angular docs Angular文档中有关$ location服务的更多信息

https://docs.angularjs.org/guide/$location https://docs.angularjs.org/guide/$location

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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