0

I would like to populate a select with an array in AngularJS. I have an error : TypeError: meanService.getMeanStuff is not a function but I don't find where is the problem...

This is my view :

<div id="idName" ng-controller="controllerName">
    Here is my select :
    <select ng-model='modelTypeSelect' ng-options="n for n in meanStuff track by n"></select>
</div>

Controller :

d3DemoApp.controller('controllerName',function($rootScope,$scope, meanService) {
    $scope.meanStuff = meanService.getMeanStuff();
    $scope.$watch('modelTypeSelect',function(newVal){
        $rootScope.$broadcast(':parameterName',{choice:newVal});
    });
});

Service :

d3DemoApp.service('meanService', function() {
    this.getMeanStuff = function() {
        return (["data1", "data2", "data3"])
    };
}).service('dataService', function AppCtrl($http, $q) {
    this.getCommitData = function(param) {
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: param
        }).
        success(function(data) {
            deferred.resolve({
                chartData: data,
                error: ''
            });
        }).
        error(function(data, status) {
            deferred.resolve({
                error: status
            });
        });
        return deferred.promise;
    };

});

Thanks.

1
  • in your plunker order of js files included incorrectly. Commented May 16, 2016 at 7:52

2 Answers 2

1

You have wrong order of scripts first you need to include angular then create the module then include your controllers that use d3DemoApp module:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script>
  var d3DemoApp = angular.module('d3DemoApp', []); 
</script>
<script src="ControllerFilterListType.js"></script>
<script src="ServiceFilterListType.js"></script>

https://plnkr.co/edit/bm8UOrT1mjJyJguAXUUy?p=preview

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your response, It works on Plunker but on my project, I have an error on $scope.meanStuff = meanService.getMeanStuff();, it says that angular.js:9563 TypeError: meanService.getMeanStuff is not a function. would you know where the problem might be? I'm going crazy ...
Try recreate the problem in plunker.
0

Removed the brackets around the return. So:

return ["data1", "data2", "data3"]

2 Comments

Hello, I have the same problem.
You don't need to remove the brackets (1) === 1

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.