首页 > 解决方案 > 未知提供者:attrsProvider <- attrs

问题描述

从我的子控制器访问 attrs 时出现此错误

> Unknown provider: attrsProvider <- attrs   

这是我的代码:

var app = angular.module('plunker', []);
//parent controller
app.controller('MainCtrl', function($scope, $controller, $attrs ) {
//extending child controlller
  angular.extend(this, $controller('MainCtrl2', {$scope: $scope}));
});

//child controller
app.controller('MainCtrl2', function($scope, $controller, $attrs) {
 console.log($attrs)
});

但是从父控制器访问 attrs 工作正常...

标签: javascriptangularjs

解决方案


你也必须提供$attrs

angular.extend(this, $controller('MainCtrl2', {$scope: $scope, $attrs}));

推荐阅读