Created
August 14, 2015 04:01
-
-
Save mori-dev/5e4f96093faf7d31725f to your computer and use it in GitHub Desktop.
AngularJS のディレクティブのコントローラでインジェクトするサービスを動的に決めるには ref: http://qiita.com/mori-dev@github/items/1dbb3a7d96ce6a0d4549
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <my-hoge filter="AaaFilter"></my-hoge> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class HogeDirectiveController { | |
| constructor($injector) { | |
| this.$injector = $injector; | |
| } | |
| setFilter(filter) { | |
| this.filter = this.$injector.get(filter); | |
| } | |
| } | |
| HogeDirectiveController.$inject = ['$injector']; | |
| function HogeDirective($parse) { | |
| return { | |
| restrict: 'E', | |
| controller: HogeDirectiveController, | |
| controllerAs: 'dctrl', | |
| scope: {}, | |
| link: function (scope, element, attrs, controller) { | |
| scope.dctrl.setFilter(attrs.filter); | |
| }, | |
| template: ` | |
| <input ng-model="dctrl.filter.piyopiyo"> | |
| ` | |
| }; | |
| } | |
| angular.module('MyAdmin').directive('myHoge', HogeDirective) | |
| export default HogeDirective; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment