AngularJS参数'fn'不是函数,未定义

时间:2018-07-17 15:01:44

标签: javascript angularjs

我在AngularJS 1.6上遇到问题,错误消息说:

  

错误:[ng:areq]参数'fn'不是函数,未定义

我知道我的testService有问题,请帮助查找问题

./ app.js

-syntax error

./ services / test.service.js

import angular from 'angular';
import uiRouter from 'angular-ui-router';
import Components from './components/components';
import { TestComponent } from './test/test.component';
import { ApiConstant } from './constants';
import { TestService } from './services';

angular.module('myApp', [
    uiRouter,
    Components
  ])
  .component('testPage', TestComponent)
  .service('TestService', TestService)
  .constant('ApiConstant', ApiConstant)
  .config(($stateProvider) => {
    'ngInject';
    $stateProvider
      .state('home', {
        url: '',
        template: '<test-page></test-page>'
      });
  });

./ services / index.js

export const TestService = (ApiConstant) => {
  'ngInject';

  this.test = function() {
    console.log(ApiConstant);
    return ApiConstant;
  };
};

./ constants / api.js

export * from './test.service';

./ constants / index.js

export const ApiConstant = {
  url: 'test'
};

./ components / test.component.js

export * from './api.constant';

./ components / test.controller.js

import template from './test.component.html';
import controller from './test.controller';

export const TestComponent = {
  template,
  controller
};

所以ApiConstant可以正常工作,但是TestService会产生错误,当我将Controller从TestService中删除TestService时,它可以正常工作吗?

1 个答案:

答案 0 :(得分:0)

模块依赖项应为字符串:

  

错误

angular.module('myApp', [
    uiRouter,
    Components
  ])

应该是:

angular.module('myApp', [
    'uiRouter',
    'Components'
  ])