javascript - Why don't I get the same output 3 times in the attached code? -
i trying understand features in angularjs. wrote codepen of attempt (http://codepen.io/ssj666/pen/xbgkxx).
my code:
<!doctype html public "-//ietf//dtd html 2.0//en"> <html> <head> <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> </head> <body> <div ng-app="test" ng-controller="testctrl"> <ul> <li ng-repeat="x in names"> {{ x.name + ', ' + x.country }} </li> </ul> </div> <div ng-app="t" ng-controller="testctrl"> <ul> <li ng-repeat="x in names"> {{ x.name + ', ' + x.country }} </li> </ul> </div> <div ng-app="t2" ng-controller="tctrl"> <ul> <li ng-repeat="x in names"> {{ x.name + ', ' + x.country }} </li> </ul> </div> <script> var app = angular.module('test', []); app.controller('testctrl', function($scope, $http) { $http.get("http://www.w3schools.com/angular/customers.php") .success(function (response) {$scope.names = response.records;}); }); </script> <script> var app = angular.module('t', []); app.controller('testctrl', function($scope, $http) { $http.get("http://www.w3schools.com/angular/customers.php") .success(function (response) {$scope.names = response.records;}); }); </script> <script> var app = angular.module('t2', []); app.controller('tctrl', function($scope, $http) { $http.get("http://www.w3schools.com/angular/customers.php") .success(function (response) {$scope.names = response.records;}); }); </script> </body> </html>
i hope there isn't typo crashing everything, if dont see it. possible single angularjs controller control tags different ng-app-names? why not possible second controller same om scope attributes of different tag (with different ng-app-name)?
i investigating if question possible duplicate.
instead of using different apps, want use 1 app different controllers. see project, use 1 project different classes, or 1 project different html templates or whatever can think of. app parent, controllers children. controllers need have unique names though!
Comments
Post a Comment