Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Very new to AngularJS and below is my code. Trying to do similar to railscast episode #401 on ActionController::Live but as i am trying this with angularJS, not able to achieve the expected result.

This is my controller method for users/index

include ActionController::Live
      def index
      @users = User.all
       response.headers['Content-Type'] = "text/event-stream"
        3.times do |n|
        response.stream.write "data: hi #{n} ... \n\n"
        sleep 3
       end
       response.stream.close
      end

Regular index.html.erb

<div ng-controller="testingUserIndexCtrl">
<h1> Listing users</h1>
<table>
  <thead>
    <tr>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>

  <tbody>
    <% @users.each do |user| %>
      <tr>
        <td><%= link_to 'Show', user %></td>
        <td><%= link_to 'Edit', edit_user_path(user) %></td>
        <td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
      </tr>
    <% end %>
  </tbody>
</table>

<br>

<%= link_to 'New User', new_user_path %>
</div>

In my users.js.coffee i have below code

@testingUserIndexCtrl = ($scope, $window) ->
  $scope.source = new EventSource('/users') 
  $scope.source.addEventListener , (e) ->
  $window.alert(e.data)

But i can see output as just

data: hi 0 ... 

data: hi 1 ... 

data: hi 2 ... 

Very new to angularJS, so i just want to see my response stream in alerts form using angularJS.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.