I've bootstrapped Angular onto my Rails project using this guide
And in the console I get a "exampleApp running", So Angular is working. Next step was to try and include a template into the index file.
I've added this to the index.html.erb
<div ng-include="'templates/header.html'"></div>
But it doesn't include the template.
This is my structure
- app
- assets
- javascripts
- angular-app
- app.js.coffee
- templates
- angular-app
- javascripts
- assets
This is the content of my app.js.coffee file
@app = angular.module('app', [
# additional dependencies here, such as restangular
'templates'
])
# for compatibility with Rails CSRF protection
@app.config([
'$httpProvider', ($httpProvider)->
$httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content')
])
@app.run(->
console.log 'angular app running'
)
But I'm not seeing the 'angular app running' message in the console, so I think this file isn't doing anything.
Any ideas on what the problem is?
// edit.
This was my index.html
<div ng-app='app.exampleApp' ng-controller='ExampleCtrl'>
<p>Value from ExampleCtrl:</p>
<p>{{ exampleValue }}</p>
</div>
<div ng-include="'templates/header.html'"></div>
And I realized that I wasn't loading the template in the ng-app so obviously it wasn't working.
I moved the include in the ng-app and now I'm getting a 404 error. So at least its trying to include the file.
// edit 2
By changing the path to the template to <div ng-include="'assets/angular-app/templates/header.html'"></div> it's including the file.