Javascript 如何使用angular重定向用户
当用户单击提交按钮时,我尝试将angular以这种方式转发到我的web应用程序中: html代码Javascript 如何使用angular重定向用户,javascript,angularjs,Javascript,Angularjs,当用户单击提交按钮时,我尝试将angular以这种方式转发到我的web应用程序中: html代码 <tr ng-controller="fCtrl as fiche"> <td> <span ng-hide="fiche.canBeEdited()"></span> <span ng-show="fiche.canBeEdited()">
<tr ng-controller="fCtrl as fiche">
<td>
<span ng-hide="fiche.canBeEdited()"></span>
<span ng-show="fiche.canBeEdited()">
<input type="checkbox" name="qualif0" ng-model="qualif0" >
</span>
</td>
<td>
<span ng-hide="fiche.canBeEdited()"></span>
<span ng-show="fiche.canBeEdited()">
<input type="checkbox" name="qualif1" ng-model="qualif1" >
</span>
</td>
<td>
<span ng-hide="fiche.canBeEdited()"></span>
<span ng-show="fiche.canBeEdited()">
<input type="checkbox" name="commentaire" ng-model="commentaire" >
</span>
</td>
<td>
<a href="#" ng-click="fiche.editLine()" title="Modifier">Modifier</a>
<button type="submit" class="btn btn-primary" ng-show="fiche.canBeEdited()" ng-click="fiche.submitEdit(qualif0, qualif1, commentaire)">Modifier</button>
</td>
</tr>
但是,这是行不通的
请问如何修理这个
提前谢谢如果我想考虑角度重定向,我会先听<代码> $RouTeCudiestART/<代码>事件(我想也有<代码> $LooCuffestART/<代码>),并从这里使用<代码> $List.PATH()/代码>重定向。这样,我将防止在重定向之前从角度加载路由 这是我的一些旧代码: 下面的代码表明,它需要位于高级作用域(例如,包含所有页面组件的作用域。容器)中,因为它需要在所有视图中处于活动状态
// listening to the routeChangeStart event. It is triggered every time the router navigates between views
$rootScope.$on('$routeChangeStart', function(event, newLocation, oldLocation)
// check if the route is allowed
if( newLocation !== '/private' ){
// if not we stop the navigation and redirect to something else;
event.preventDefault();
$location.path('/notAuthorized');
}
});
使用
$location服务为的只读部分提供getter方法
URL(absUrl、协议、主机、端口)和的getter/setter方法
url、路径、搜索、哈希:
为什么不从angular使用$location.path?@VinodLouis,谢谢你的建议,但这里还有一个问题,我收到的是空白参数
ng click=“fiche.submittedit(qualif0,qualif1,commentaire)”
@user3821280你指定的ng controller=“FicheCtrl as fiche”
但我可以看到您的控制器名为fCtrl
。您确定调用了submitEdit(…)
函数吗?你能提供小提琴或弹琴等吗?@razvan,它已被更新。@user3821280尝试使用$scope
而不是this
。尝试查看它是否可以在不使用别名的情况下工作。尝试删除type=“submit”
。还有一个附带问题:重定向是否应该涉及服务器?谢谢,但这里还有一个问题,我收到的是空白参数ng click=“fiche.submittedit(qualif0,qualif1,commentaire)”
。请给我们写下最后的代码,您可以将您的建议放入其中吗,为了让它更容易理解,请检查和以获取更多信息。我需要将参数传递到函数中以重定向用户。但是,我把它们都弄空了!如果qualif0
是$scope
的一部分,您甚至不需要将它们作为参数进行pas。您可以在事件处理程序中使用$scope.qualif
。你的代码正在运行吗?如果将create a plunker.co放入,则可能更容易确定问题的根源。qualif0
表示ng模型
。我试图得到它的值,并把它作为那个函数的参数。但是,这是行不通的:/我明白了。您的函数是否实际执行?如果是,请尝试读取该处理程序中的$scope.qualif0
,并查看使用console.log或调试器时的值。我已尝试使用此警报(commentaire)代码>,我得到一个空值。
// listening to the routeChangeStart event. It is triggered every time the router navigates between views
$rootScope.$on('$routeChangeStart', function(event, newLocation, oldLocation)
// check if the route is allowed
if( newLocation !== '/private' ){
// if not we stop the navigation and redirect to something else;
event.preventDefault();
$location.path('/notAuthorized');
}
});
// get the current path
$location.path();
// change the path
$location.path('/newValue')