AngularJS の現在の $scope からコントローラー名を取得する方法はありますか?
ベストアンサー1
これが良い解決策かどうかはわかりませんが、$scope.controllerName
このテクニックを使用して注入することができました:
app.config(['$provide', function ($provide) {
$provide.decorator('$controller', [
'$delegate',
function ($delegate) {
return function(constructor, locals) {
if (typeof constructor == "string") {
locals.$scope.controllerName = constructor;
}
return $delegate.apply(this, [].slice.call(arguments));
}
}]);
}]);
それから
app.controller('SampleCtrl', ['$scope', '$log', function ($scope, $log) {
$log.log("[" + $scope.controllerName +"] got here");
}]);