AngularJS_Basics2_Application_ Module_And_Controller_In_JS_Files

<!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="myCtrl"> {{ firstName + " " + lastName }} <ul> <li ng-repeat="x in names"> {{ x.name + ', ' + x.country }} </li> </ul> </div> <script src="myApp.js"></script> <script src="myCtrl.js"></script> </body> </html> <!-- ---------------------------------- myApp.js ---------------------------------- var app = angular.module("myApp", []); ---------------------------------- myCtrl.js ---------------------------------- app.controller("myCtrl", function($scope) { $scope.firstName = "John"; $scope.lastName= "Doe"; $scope.names = [ {name:'Jani',country:'Norway'}, {name:'Hege',country:'Sweden'}, {name:'Kai',country:'Denmark'} ]; }); ------------------------------------ personController.js (can use single js file for both app and controller definitions) ------------------------------------ angular.module("myApp", []).controller("myCtrl", function($scope) { $scope.firstName = "John"; $scope.lastName= "Doe"; $scope.names = [ {name:'Jani',country:'Norway'}, {name:'Hege',country:'Sweden'}, {name:'Kai',country:'Denmark'} ]; }); -->

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.