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.

Trying to learn angular. Started with the tutorial.

I have a coffeescript file, that is compiled on the server and then minified.
This works:

phonecatApp = angular.module('phonecatApp',[])

PhoneListCtrl = ($scope) ->
    $scope.phones = [
        {
            name: 'Nexus S',
            snippet: 'Fast just got faster with Nexus S.'
        }
        {
            name: 'Motorola XOOM™ with Wi-Fi',
            snippet: 'The Next, Next Generation tablet.'
        }
        {
            name: 'MOTOROLA XOOM™',
            snippet: 'The Next, Next Generation tablet.'
        }
    ]
PhoneListCtrl.$inject = [
    "$scope"
]
phonecatApp.controller 'PhoneListCtrl', PhoneListCtrl

But this (added the arrow "->") doesn't

->
    phonecatApp = angular.module('phonecatApp',[])

    PhoneListCtrl = ($scope) ->
        $scope.phones = [
            {
                name: 'Nexus S',
                snippet: 'Fast just got faster with Nexus S.'
            }
            {
                name: 'Motorola XOOM™ with Wi-Fi',
                snippet: 'The Next, Next Generation tablet.'
            }
            {
                name: 'MOTOROLA XOOM™',
                snippet: 'The Next, Next Generation tablet.'
            }
        ]
    PhoneListCtrl.$inject = [
        "$scope"
    ]
    phonecatApp.controller 'PhoneListCtrl', PhoneListCtrl

I tried a lot already but nothing works

HTML looks like this

<html ng-app="phonecatApp">
<head>
  ...
  <script src="...com/.../angularjs/1.2.16/angular.min.js"></script>
  <script src="js/controllers.js"></script>
</head>
<body>
  <div class="container" ng-controller="PhoneListCtrl">
    <ul>
      <li ng-repeat="phone in phones">
        {{phone.name}}
        <p>{{phone.snippet}}</p>
      </li>
    </ul>
  </div>
</body>
</html>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Do this for a document ready

$ ->
    var x = 5; // your code here

I dont think you need to do this though since angular bootstraps when the page is loaded, unless you are using angular.bootstrap() before the DOM is loaded.

share|improve this answer
    
damn it, don't know why I forgot the $ –  Allisone May 25 at 13:00

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.