AngularJS areq 不是函数的错误

AngularJS error ng areq not a function

我试图让我的元控制器动态更改元标记,但在控制台中我得到 error ng areq not a function。我在 Whosebug 上搜索了类似的问题,但 none 的解决方案是针对我的问题的。我的 HTML:

中有这些标签
    <html  ng-app="WebApp" >
    <head  ng-controller="MetaDataCtrl">
    <meta name="description" content="{{ meta.tags.description }}">
</head>
<body >

    <div ng-include='"templates/header.html"'></div>
    <div ng-view></div>

</body>
</html>

Main.js

var app = angular.module('WebApp', [
  'ngRoute'
]);

/**
 * Configure the Routes
 */
app.config(['$routeProvider', '$locationProvider', function($routes, $location) {
 $location.html5Mode(true).hashPrefix('!');
  $routes
    // Home
    .when("/", {templateUrl: "partials/home.html",  
      controller: "PageCtrl",
      metadata: {
           title: 'This is my title',
           description: 'This is Desc.' }

    })
}]);

app.controller('PageCtrl', function (/* $scope, $location, $http */) {

});

.controller('MetadataCtrl', function ($scope, metadataService) {
   $scope.meta = metadataService;
});

没有这样的服务metadataService而且您没有自己定义。但是,看起来您只需要访问当前路由 metadata 对象。在这种情况下,它很容易做到,因为它是 $route 服务的一部分。您还应该设置一个侦听器以在路由更改时更新全局 meta 对象:

app.run(['$rootScope', function($rootScope) {
    $rootScope.$on('$routeChangeSuccess', function(event, current) {
        $rootScope.meta = current.metadata;
    });
}]);

演示: http://plnkr.co/edit/nQfqNWvoYQQElv909uZF?p=preview