0

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) ->
]
3
  • why do you have two controllers with the same name? Commented Sep 4, 2014 at 7:05
  • I just noticed that and am resolving it now. Thanks Commented Sep 4, 2014 at 7:09
  • I think this tutorial is incorrect. It tells the reader to create 2 directories with the same name. Commented Sep 4, 2014 at 7:10

2 Answers 2

1

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.

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

Comments

0

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.

Comments

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.