未知提供者:attrsProvider <-attrs

时间:2019-03-22 07:24:52

标签: javascript angularjs

从我的子控制器访问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可以正常工作...

1 个答案:

答案 0 :(得分:0)

您还必须提供$attrs

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