javascript - How to redirect to another page on ng-click using angularjs or coffeescript? - Stack Overflow

I am doing some tasks now in angularjs and coffeescript. I have a requirement like: I have couple of bu

I am doing some tasks now in angularjs and coffeescript. I have a requirement like: I have couple of buttons in my html page like:

<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>

If I click on Button1, then it should redirect to another page(like: '/test1.html'), similarly, if I click on Button2, then it should redirect to another page(like: '/test2.html'). How can I do this in AngularJS/CoffeeScript ?

If I do in my coffeescript file, I am getting the below error:

app = angular.module('myApp', dependencies)
app.controller 'WizardController', [
  '$scope',
  ($scope) ->
  $scope.button1 = ->
    window.location = '/test1.html'
    return

    $scope.button2 = ->
    window.location = '/test2.html'
    return
  ]

but it is giving pilation error at return statement: Compilation error: Parse error on line 103: Unexpected 'TERMINATOR'

I am doing some tasks now in angularjs and coffeescript. I have a requirement like: I have couple of buttons in my html page like:

<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>

If I click on Button1, then it should redirect to another page(like: '/test1.html'), similarly, if I click on Button2, then it should redirect to another page(like: '/test2.html'). How can I do this in AngularJS/CoffeeScript ?

If I do in my coffeescript file, I am getting the below error:

app = angular.module('myApp', dependencies)
app.controller 'WizardController', [
  '$scope',
  ($scope) ->
  $scope.button1 = ->
    window.location = '/test1.html'
    return

    $scope.button2 = ->
    window.location = '/test2.html'
    return
  ]

but it is giving pilation error at return statement: Compilation error: Parse error on line 103: Unexpected 'TERMINATOR'

Share Improve this question asked Dec 14, 2015 at 9:42 DhanaDhana 7233 gold badges14 silver badges41 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

You can redirect straight from your HTML page:

<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>

Or else in your code you should remove the ';' from the

ng-click

as in:

<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>

I will also check the indentation in your coffeescript as it tend to be a bit fuzzy.

app = angular.module('myApp', dependencies)
app.controller 'WizardController', [ '$scope', '$location',
($scope, $location) ->
  $scope.button1 = ->
    $location.path('/test1.html')

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744226471a4564030.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信