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

Error: [ng:areq] Argument 'ActsController' is not a function, got undefined

本文关键字:函数 未定义 ActsController ng 参数 错误 areq      更新时间:2023-09-26

我一直收到错误:错误:[ng:areq]参数"ActsController"不是函数,未定义。我见过其他几个人也有类似的错误,通常是因为打字错误。但我想我在任何地方都没有拼错控制器的名字。

顺便说一句,我正在使用Angular和Rails。

app.js

var controllers, snowball_effect;
snowball_effect = angular.module('snowball_effect', [
    'templates', 
    'ngRoute', 
    'ngResource',
    'controllers'
]);
snowball_effect.config([
  '$routeProvider', function($routeProvider) {
    return $routeProvider
    .when('/', {
      templateUrl: "static_pages/index.html",
      controller: 'StaticPagesController'
    })
    .when('/acts/index', {
        templateUrl: "acts/index.html",
        controller: 'ActsController'
    });
  }
]);

controllers = angular.module('controllers', []);
controllers.controller("StaticPagesController", ['$scope', function($scope) {}]);
controllers.controller("ActsController", [
  '$scope', 
  '$routeParams', 
  '$location', 
  '$resource', 
  function($scope,$routeParams,$location,$resource) {
    $scope.acts = [
      {
        id: 1, 
        name: "Plant a Flower", 
        description: "Plant a flower in your garden or along the street."
        inspires: 1
      }
    ];
}]);

javascript/templates/acts/index.html

<div class="actions_body">
  <h2>Listing Actions</h2>
  <div ng-controller="ActsController" class="body">
    <table class="row">
      <thead>
        <tr>
          <th class="col-md-offset-1 col-md-2 active">
            <label>Name</label>
          </th>
          <th class="col-md-4">Description</th>
          <th class="col-md-2">Inspires</th>
          <th colspan="2" class="col-md-2">Modify</th>
        </tr>
      </thead>
      <tbody ng-repeat="act in acts">
        <td class="col-md-offset-1 col-md-2">{{act.name}}</td>
        <td class="col-md-4">{{act.description}}</td>
        <td class="col-md-2">{{act.inspires}}</td>
        <td><a href="#">Edit</a></td>
        <td><a href="#">Delete</a></td>
      </tbody>
    </table>
    <br>
    <a href="#">New Action</a>
  </div>
</div>

编辑:

现在我想起来了,我也遇到了另一个问题。每当我刷新页面时,主要部分都会消失。我想这个问题更多的是针对Rails/Angular的。

views/home/index.html.erb

<div ng-app="snowball_effect">
  <div class="view-container">
    <div ng-include="'layouts/index.html'"></div>
  </div>
</div>

assets/javascript/templates/layouts/index.html

<div ng-include="'layouts/navigation.html'"></div>
<div ng-view class="view-frame animate-view"></div>

assets/javascript/templates/static_pages/index.html

<div class="body">
  <div class="container">
    <div class="introduction">
      <h1>Welcome to Snowball Effect</h1>
    </div>
    <div class="body">
      <h2>A social media platform that brings people together in a spirit of community service.</h2>
    </div>
  </div>
</div>

因此,在layout/index.html中,导航栏加载良好,但ng视图仅在第一页加载后加载。

index.html中是否包含app.js??

<script src="js/app.js"></script>