0

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;
});
}]);

})();

3 Answers 3

3

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) 
Sign up to request clarification or add additional context in comments.

1 Comment

Exactly, what I failed to detect.
0

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) ...

Comments

0

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>

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.