Reputation: 759
I am trying some angularjs tutorials and dont know why the dropdown does not populate.
I get an error in angular.js file
TypeError: undefined is not a function.
if ($rootScope.$broadcast('$locationChangeStart', newUrl,
oldUrl).defaultPrevented) {
below is my code.
<!DOCTYPE html>
<html>
<head>
<link rel="" type="text/css" href="bootstrap.min.js" />
</head>
<body ng-app = "subtitle" ng-controller="loginController">
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="app.js"></script>
<select ng-model="collections" ng-options="item.Id as item.Name for item in languages">
<option value="">Select Account</option>
</select>
</body>
</html>
(function(){
var app = angular.module('subtitle',[]);
app.controller('loginController', ['$http','$scope',function($scope,$http) {
$scope.collections = null;
$scope.languages = [];
$http.get('http://lapi.cd.com/masterdata?type=languages').success(function(data) {
$scope.languages = data;
});
}]);
})();
Upvotes: 0
Views: 121
Reputation: 4212
It might help you!!! plnker
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.js"></script>
<script>
var app = angular.module('subtitle', []);
app.controller('loginController', ['$http', '$scope',
function($http,$scope) {
$scope.collections = null;
$scope.languages = [];
$http.get('http://lapi.cd.com/masterdata?type=languages').success(function(data) {
$scope.languages = data;
});
}
]);
</script>
</head>
<body ng-app="subtitle" ng-controller="loginController">
<select ng-model="collections" ng-options="item.Id as item.Name for item in languages">
<option value="">Select Account</option>
</select>
</body>
</html>
Upvotes: 0
Reputation: 605
First of all, the order of injections you make is not right. It must be fixed, as shown below:
app.controller('loginController', ['$scope', '$http' , function($scope, $http) { ... }]);
('ctrlName', ['A', 'B', function(A, B) ...
Upvotes: 0
Reputation: 17064
You have switched the order of the variables in the controller:
app.controller('loginController', ['$http','$scope',function($scope,$http)
Switch to:
app.controller('loginController', ['$http','$scope',function($http,$scope)
Upvotes: 3