0

I am using Rails with Angularjs . So, i have link called "Notes" and when i click "Note" it takes me to url "http://localhost:3000/#/notes" and renders some templates through angularjs. When i reload the page , the templates didn't reload and when i click the link "Note" again then only it renders those templates.

So my simple question is On reloading the page , why all the contents that is rendered through angularjs disappears and how to fix this.

Updated

-javascript
   -index.html
   -routes.js

-view
   -course
      -index.html

view/course/index.html

<div class="row">
  <div ng-include="'index.html'"></div>
</div>

javascript/index.html

<div class="nav-list">
  <a ui-sref="notes"> Notes </a>
  <a ui-sref="users"> Users </a>
</div>

<div class="main-wrapper">
  <ui-view></ui-view>
</div>

javescript/routes.js

....
    .state('notes', {
      url: '/notes',
      templateUrl: 'template/pages/notes/index.html',
      controller: 'NotesIndexController'
    })
    .state('users', {
      url: '/users',
      templateUrl: 'template/pages/users/index.html'
    })
...

I changed the above scenario to this

view/course/index.html

<div class="row">
  <div class="nav-list">
      <a ui-sref="notes"> Notes </a>
      <a ui-sref="users"> Users </a>
    </div>

    <div class="hero-wrapper">
      <div class="hero-content">
        <div class="hero"></div>
      </div>
    </div>

    <div class="main-wrapper">
      <ui-view></ui-view>
    </div>
</div>

This fixed my problem but what is the difference between above two scenarios . Why it is behaving differently . Thanks

1
  • pls see if there are any error in console of a browser Commented Jan 15, 2016 at 15:26

1 Answer 1

2

You need to troubleshoot each piece of your application separately. You don't have a "Rails and AngularJS" problem; you have either a problem with your Rails API (which is serving up JSON to Angular) or you have a problem with your Angular client (which is receiving proper data from your API but isn't displaying it properly) -- or both.

I'd start at the Rails side; use an API testing tool like Cocoa Rest Client to simulate requests to the Rails API and ensure the response data is in the format you'd expect. Once you've verified that, you've reduced this from a maybe-also-Rails problem to a pure Angular problem, and you can troubleshoot the Angular app in isolation (eg. by feeding it dummy JSON instead of having it talk to the Rails app).

Good luck!

Sign up to request clarification or add additional context in comments.

1 Comment

i fixed my problem and updates the question. Can you explain me why it is happening?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.