Javascript 如何使用angularjs或coffeescript重定向到ng click上的其他页面?

Javascript 如何使用angularjs或coffeescript重定向到ng click上的其他页面?,javascript,html,angularjs,coffeescript,Javascript,Html,Angularjs,Coffeescript,我现在正在用angularjs和coffeescript做一些任务。我有这样的要求:我的html页面中有两个按钮,如: <div> <button type="button" class="btn btn-default" ng-click="button1();">Button1</button> <button type="button" class="btn btn-default" ng-click="button2();">

我现在正在用angularjs和coffeescript做一些任务。我有这样的要求:我的html页面中有两个按钮,如:

<div>
    <button type="button" class="btn btn-default" ng-click="button1();">Button1</button>
    <button type="button" class="btn btn-default" ng-click="button2();">Button2</button>
</div>

但它在返回语句中给出了编译错误:编译错误:第103行的解析错误:意外的“终止符”

您可以直接从HTML页面重定向:

<div>
  <button type="button" class="btn btn-default" ng-href="/test1.html">Button1</button>
  <button type="button" class="btn btn-default" ng-href="/test1.html">Button2</button>
</div>

您可以直接从HTML页面重定向:

<div>
  <button type="button" class="btn btn-default" ng-href="/test1.html">Button1</button>
  <button type="button" class="btn btn-default" ng-href="/test1.html">Button2</button>
</div>

ng href是一个很好的解决方案,但需要注意的是:在使用angular时不要使用window.location,只使用$location.Hi谢谢大家,我已经像上面那样做了,但我仍然得到错误(在$location.path行):第218行解析错误:意外的“缩进”,如果添加ng href,它也不起作用。正如我在帖子中所说,缩进在咖啡脚本中非常重要。检查我编辑的js文件,也在你的文件中,选择所有,然后将缩进转换为空格。缩进错误现在已解决,但如果我使用上面的代码,我仍然无法重定向到另一个页面。错误是:未捕获错误:未知提供程序:$controllerProvider from myApp,并且$scope未定义href是一个很好的解决方案,但需要注意的是:在使用angular时不要使用window.location,只使用$location。大家好,我已经做了如上所述的工作,但我仍然会遇到错误(在$location.path行):第218行解析错误:意外的“缩进”,如果添加ng href,它也不起作用。正如我在帖子中所说,缩进在coffeescript中非常重要。检查我编辑的js文件,也在你的文件中,选择所有,然后将缩进转换为空格。缩进错误现在已解决,但如果我使用上面的代码,我仍然无法重定向到另一个页面。错误是:未捕获错误:未知提供程序:$controllerProvider from myApp,并且未定义$scope
<div>
  <button type="button" class="btn btn-default" ng-click="button1()">Button1</button>
  <button type="button" class="btn btn-default" ng-click="button2()">Button2</button>
</div>
app = angular.module('myApp', dependencies)
app.controller 'WizardController', [ '$scope', '$location',
($scope, $location) ->
  $scope.button1 = ->
    $location.path('/test1.html')

  $scope.button2 = ->
    $location.path('/test2.html')
]