0

I am new to Angular, i am using Angular5.

I have productlist.js, having data in that file. Binded that data in the my html page, it's not working.

If i have the data in html file [ commented code in sample.html ], then it is working as expected.

productlist.js

angular.module('myShoppingList')
.controller('myCtrl', function ($scope) {


    $scope.products = ["Milk", "Bread", "Cheese"];

});

Sample.html

<div ng-app="myShoppingList" ng-controller="myCtrl">
    <ul>
        <li ng-repeat="x in products">{{x}}</li>
    </ul>
</div>

I have added the productlist.js under the head in sample.html

1
  • btw this is not angular5. this is angularjs syntax Commented Apr 29, 2018 at 7:36

2 Answers 2

3

You have few mistakes, you need to add empty dependencies to your module as follows,

angular.module('myShoppingList',[])

DEMO

angular.module('myShoppingList',[])
.controller('myCtrl', function ($scope) {
    $scope.products = ["Milk", "Bread", "Cheese"];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myShoppingList" ng-controller="myCtrl">
    <ul>
        <li ng-repeat="x in products">{{x}}</li>
    </ul>
</div>

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

2 Comments

thanks, how to change the above code into Angular5.. any links to learn ? Kindly help.. Thanks in advance..
there is no direct way to change to angular5 instead of rewriting it. You will use ngFor instead of ng-repeat. look the example here stackblitz.com/edit/…
0

When you add into html file, the following order of statement is important as well.

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

Please take into consideration the abovementioned code snippet.

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.