Reputation: 456
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.
Upvotes: 0
Views: 3036
Reputation: 66570
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
Upvotes: 1
Reputation: 5098
Removed the brackets around the return. So:
return ["data1", "data2", "data3"]
Upvotes: 0