0

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>
0

1 Answer 1

1

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.

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

1 Comment

damn it, don't know why I forgot the $

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.