0
votes

I was following a tutorial on implementation of angular and rails and I ran into problems performing data binding. I followed the tutorial perfectly but I hit a stumbling block I cannot solve. I am trying to display the value of foo in public/templates/home.html.

Here is my code:

public/templates/home.html

 Value of "foo": {{ foo }}

app/assets/angular/controllers/HomeCtrl.js.coffee

 @restauranteur.controller 'HomeCtrl', ['$scope', ($scope) ->
     $scope.foo = 'bar'
   ]

app/assets/javascripts/main.js.coffee

@restauranteur = angular.module('restauranteur', [])
@restauranteur.config(['$routeProvider', ($routeProvider) ->
  $routeProvider.
    otherwise({
      templateUrl: '../templates/home.html',
      controller: 'HomeCtrl'
    }) 
])

app/assets/javascripts/angular/controllers/HomeCtrl.js.coffee

@restauranteur.controller 'HomeCtrl', ['$scope', ($scope) ->
]
2
why do you have two controllers with the same name? - apneadiving
I just noticed that and am resolving it now. Thanks - chopper draw lion4
I think this tutorial is incorrect. It tells the reader to create 2 directories with the same name. - chopper draw lion4

2 Answers

1
votes

The tutorial I was following incorrectly told me to create 2 controllers with the same name. Once I deleted the controller app/assets/angular/controllers/HomeCtrl.js.coffee I was good to go.

0
votes

Check and see if main.js.cofee file is included, in your chrome console under sources tab. I also had the same issue. This issue comes when you do //=require ./angular or something like that. If you want the file to get included, then just paste it under app/assets/angular directory and after that you might have to shift your angular directory inside app/assets/javascript directory.