Curriculum
Course: AngularJS
Login

Curriculum

AngularJS

AngularJS Tutorial

0/65
Text lesson

Controllers In External Files

Another Example

In the next example, we will create a new controller file.

angular.module(‘myApp’, []).controller(‘namesCtrl’, function($scope) {
  $scope.names = [
    {name:’Jani’,country:’Norway’},
    {name:’Hege’,country:’Sweden’},
    {name:’Kai’,country:’Denmark’}
  ];
});

Then, we will utilize the controller file within an application.

AngularJS Example

<div ng-app=”myApp” ng-controller=”namesCtrl”>

<ul>
  <li ng-repeat=”x in names”>
    {{ x.name + ‘, ‘ + x.country }}
  </li>
</ul>

</div>

<script src=”namesController.js”></script>