1

I'm taking tutorial in CodeSchool about angular and I try to create my own experiment in html5 and angular new version in vs2012.

I try to test angular repeat but the problem is HTML5 can't render my angular.

When I try to run my page, the repeater only show the angular statement {{item.name}}:{{item.quantity}} not the result. Why? -"show code below"

Angular script :

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>

application.js :

<script type="text/javascript" src="Scripts/application.js"></script>

$(function () {
    var app = angular.module('zaskarCorp', []);
    app.controller('kirito', function ($scope) {
        $scope.items = [{
            "name": "dual sword",
            "quantity": 2
        }, {
            "name": "gun",
            "quantity": 1
        }, {
            "name": "laser sword",
            "quantity": 1
        }];
    });
});
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" data-ng-app="zaskarCorp">

<head>
  <title></title>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
  <script type="text/javascript" src="Scripts/application.js"></script>
</head>

<body data-ng-controller="kirito">
  <ul>
    <li data-ng-repeat="item in items">
      <span>{{item.name}}:{{item.quantity}}</span>
    </li>
  </ul>
</body>

</html>

As you can see I add data- in my angular because I use html5. -"I hate warnings"

6
  • You've answered your own question. You've added data- to the angular directive thus no longer making it an angular directive. Ask yourself, how do you expect that angular knows what data-ng-controller means? It doesn't, and since the directive is not now being processed your angular expressions are not being evaluated. Commented Nov 8, 2014 at 1:58
  • Are you receiving an error? You have var app = agular.module..., do you mean var app = angular.module...? You also have $(funtion()..., do you mean (function()...? Commented Nov 8, 2014 at 2:01
  • 2
    @rism, angular normalizes directive names, and data- is accepted specifically for this reason. Commented Nov 8, 2014 at 2:01
  • @rism It's still the same even if you remove the data-. Commented Nov 8, 2014 at 2:02
  • 1
    @NewDev Yep you're right. docs.angularjs.org/guide/directive Commented Nov 8, 2014 at 2:03

3 Answers 3

2

Your code has a number of typos and errors:

  • funtion instead of function
  • agular instead of angular
  • no jQuery included, but you call $(function(){...})

Here's a plunker with your code working.

Also, for future reference, if you remove .min from the angular source, it makes it easier to debug.

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

1 Comment

The problem is the $ from $(function(){});, I thought Angular is extension of jQuery.
1

Please add this directive to your body tag: data-ng-app="zaskarCorp"

Also, you have some misspellings in your javascript code.

2 Comments

It's not working, sorry there is no misspellings I just miss type when putting it here.
Maybe you should include jQuery or remove "$(function..." completely? I removed that and it works.
1

Without using jQLite your code will look like this:

var app = angular.module('zaskarCorp', []);

app.controller('kirito', function ($scope) {

$scope.items = [
    {
        "name": "dual sword",
        "quantity": 2
    }, 
    {
        "name": "gun",
        "quantity": 1
    }, 
    {
        "name": "laser sword",
        "quantity": 1
    }];
});

Full code:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" data-ng-app="zaskarCorp">

<head>
  <title></title>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
  <script>
    var app = angular.module('zaskarCorp', []);

    app.controller('kirito', function($scope) {

      $scope.items = [{
        "name": "dual sword",
        "quantity": 2
      }, {
        "name": "gun",
        "quantity": 1
      }, {
        "name": "laser sword",
        "quantity": 1
      }];
    });
  </script>
</head>

<body data-ng-controller="kirito">
  <ul>
    <li data-ng-repeat="item in items">
      <span>{{item.name}}:{{item.quantity}}</span>
    </li>
  </ul>
</body>

</html>

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.