ng-table:Argument" controller"不是一个功能,得到了对象

时间:2016-11-29 14:42:15

标签: javascript angularjs ngtable

我试图在Angular 1.5应用中使用ng-table并遇到了我似乎无法修复的问题。使用此处的基本设置(由于我的应用程序具有不同的组件设置略有改动),我不断收到相同的错误:

  

错误:[ng:areq] Argument' MyTableController'不是一个函数,得到了对象

我的代码如下。任何帮助将不胜感激。

table.controller.js

import 'ng-table';

class MyTableController {
    constructor(NgTableParams) {
        var data = [
            { name: "Moroni", age: 50 },
            { name: "Enos", age: 34 }
        ];

        this.tableParams = new NgTableParams({}, {
            dataset: data
        });
    }
}

MyTableController.$inject = ['NgTableParams'];

table.routes.js

routes.$inject = ['$stateProvider'];

export default function routes($stateProvider) {
  $stateProvider
    .state('table', {
      url: '/data',
      template: require('./table.html'),
      controller: 'MyTableController',
      controllerAs: 'table'
    });
}

index.js

import angular from 'angular';
import uirouter from 'angular-ui-router';

import './table.css';

import routing from './table.routes';
import MyTableController from './table.controller';
// import mainTable from './mainTable.service';
// Import other dashboard services here

export default angular.module('app.table', [uirouter])
  .config(routing)
  .controller('MyTableController', MyTableController)
  .name;

app.js

// import angular and ui-router
import angular from 'angular';
import { ngTable } from 'ng-table';
import uirouter from 'angular-ui-router';

// import CSS and bootstrap
import './app.css';
import 'bootstrap/dist/css/bootstrap.css';
// import 'font-awesome/css/font-awesome.css';

// import NavBar
import Components from './components';

// import config file and modules here
import routing from './app.config';
import home from './features/home';
import facility from './features/facility';
import dashboard from './features/dashboard';
import table from './features/data-tables';

angular.module('app', [ngTable.name, uirouter, home, facility, dashboard, table, Components])
  .config(routing);

table.html

<table ng-table="$ctrl.tableParams" show-filter="true" class="table table-condensed table-bordered">
    <tr ng-repeat="user in $data">
        <td data-title="'Name'" header-class="'text-left'" sortable="'name'" filter="{ 'name': 'text' }">
            {{user.name}}
        </td>
        <td data-title="'Age'" header-class="'text-right'" sortable="'age'" filter="{ 'age': 'text' }">
            {{user.age}}
        </td>
    </tr>
</table>

1 个答案:

答案 0 :(得分:0)

感谢Robba指出我没有正确导出控制器的愚蠢。