javascript - AngularJS Controller 中基于值的重定向

标签 javascript angularjs if-statement controller

我对 AngularJs 真的很陌生,我找不到如何执行以下操作:

用户正在 quiz.html 页面中回答问题。 每个答案都会添加到“答案”列表中。 在 Controller 中,如果我的“答案”列表包含 4 个答案,我想重定向到 result.html 页面...

if (answers.length === 4) {
    ???? }

我知道这是一个简单的问题,但我找不到任何简单的答案 谢谢!

最佳答案

您可以使用Angular $location

if (answers.length === 'whatever') {
    $location.path("/result")
}

在你的 app.js 中

$routeProvider.when('/result', {
    templateUrl: 'templates/result.html',
        controller: 'ResultCtrl'
    })...

Make sure to inject the $location into your controller.

关于javascript - AngularJS Controller 中基于值的重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28865857/

相关文章:

javascript - 使用 Angular 创建一个条目表单

java - 如何制作 if 语句来检查所有或仅一个文本字段是否为空

vba - 我有这个引用的类型不匹配错误

javascript - 在 React 中更改父级的状态时,我的子级值没有改变?

javascript - 在没有 Controller 的情况下,ng-init 真的是一种糟糕的设置变量的方法吗

javascript - Bootstrap 选项卡 - Typeerror .tab 不是函数

javascript - AngularJS ng-options 自定义属性

excel - 标记所有不包含两个给定单词的单元格

javascript - jQuery 检查输入字段内部是否有斜杠

Javascript XMLHttpRequest——只有第一个 POST 请求有效