类型错误不是AngularJS的函数

时间:2016-05-16 07:33:15

标签: javascript angularjs web-services angularjs-directive angularjs-scope

我想在AngularJS中使用数组填充select。 我有一个错误:TypeError:meanService.getMeanStuff不是一个函数,但我找不到问题所在......

这是我的观点:

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

控制器:

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

服务:

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

});

感谢。

2 个答案:

答案 0 :(得分:1)

您的脚本顺序首先需要包含angular然后创建模块然后包含使用d3DemoApp模块的控制器:

<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

答案 1 :(得分:0)

删除了返回周围的括号。所以:

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