【发布时间】:2016-01-15 04:10:35
【问题描述】:
我有一个模式,我使用自定义指令在提交后关闭模式。这行得通。接下来,我想知道如何才能以角度刷新用户所在的当前页面。我试过 $location.path("/");它可以工作,但它重定向到根页面而不是用户当前所在的任何页面。我该怎么做才能重定向到当前页面。
网址如下所示 index.angular.html#/profile/
自定义指令看起来像这样
// Custom directive to close modal upon submit
app.directive('myModal', function($location) {
return {
restrict: 'A',
link: function(scope, element, attr) {
scope.dismiss = function() {
element.modal('hide');
$location.path("/");
};
}
};
});
【问题讨论】:
-
虽然解决方案很简单?你为什么要这样做?在
angular中维护状态应该不难 -
我正在使用模式向我在 UI 中显示的数据库添加一条记录。从技术上讲,如果我只需要更新绑定到我正在显示的表的 $scope,那么只刷新我正在使用的 $scope 会更好吗?如果有怎么办?
-
您可以使用回调函数(
success) 并更新model
标签: javascript angularjs