gpt4 book ai didi

javascript - 类型错误不是 AngularJS 的函数

转载 作者:行者123 更新时间:2023-12-03 06:56:37 25 4
gpt4 key购买 nike

我想用 AngularJS 中的数组填充选择。我有一个错误: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>

Controller :

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

});

谢谢。

最佳答案

您的脚本顺序错误,首先您需要包含 Angular,然后创建模块,然后包含使用 d3DemoApp 模块的 Controller :

<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

关于javascript - 类型错误不是 AngularJS 的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37248849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com