File tree Expand file tree Collapse file tree 3 files changed +102
-1
lines changed Expand file tree Collapse file tree 3 files changed +102
-1
lines changed Original file line number Diff line number Diff line change 1- # angular-dynamic-controller
1+ # Angular Dynamic Controller
2+
3+ This directive allows you to dynamically specify a controller name to inject into html template
4+
5+ ## Installation
6+
7+ Install using ` bower `
8+
9+ bower install --save angular-dynamic-controller
10+
11+ Load the script files into your application.
12+
13+ ``` html
14+ <script src =" bower_components/angular/angular.js" ></script >
15+ <script src =" bower_components/angular-dynamic-controller/lib/angular-dynamic-controller.js" ></script >
16+ ```
17+
18+ Add this module as a dependency in your AngularJS app.
19+
20+ ``` javascript
21+ angular .module (' myApp' , [ ' aj.angular-dynamic-controller' ]);
22+ ```
23+
24+ ## Usage
25+
26+ The ` dynamicController ` directive which include the controller name dynamically.
27+
28+ To use this directive use attribute 'dynamic-controller' in the following way.
29+
30+ ``` html
31+ <tabset >
32+ <tab ng-repeat =" tab in tabs" active =tab.active >
33+ <tab-heading >{{tab.title}} </tab-heading >
34+ <div ng-include =" tab.template" dynamic-controller =" tab.controller" ></div >
35+ </tab >
36+ </tabset >
37+ ```
38+
39+ ``` javascript
40+ var myApp = angular .module (' myApp' ,[]);
41+
42+ myApp .controller (' TabCtrl' , [' $scope' , function ($scope ) {
43+
44+ $scope .tabs = [{
45+ tab .template = " main.html" ,
46+ tab .controller = " MainCtrl"
47+ }];
48+
49+ }]);
50+ ```
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " angular-dynamic-controller" ,
3+ "version" : " 1.0.0" ,
4+ "authors" : [
5+ " Aditya Jadhav <aditya.jadhav27@gmail.com>"
6+ ],
7+ "description" : " Angular directive that allows dynamically include the controller" ,
8+ "main" : " lib/angular-dynamic-controller.js" ,
9+ "moduleType" : [
10+ " globals"
11+ ],
12+ "keywords" : [
13+ " angular" ,
14+ " dynamic controller" ,
15+ " tabs" ,
16+ ],
17+ "license" : " MIT" ,
18+ "ignore" : [
19+ " demo" ,
20+ " node_modules" ,
21+ " bower_components" ,
22+ " test" ,
23+ " tests"
24+ ]
25+ }
Original file line number Diff line number Diff line change 1+ ( function ( ) {
2+
3+ 'use strict' ;
4+
5+ var module ;
6+
7+ module = angular . module ( 'aj.angular-dynamic-controller' ) ;
8+
9+ module . directive ( 'dynamicController' , [ '$controller' ,
10+ function ( $controller ) {
11+ return {
12+ restrict : 'A' ,
13+ scope : true ,
14+ link : function ( scope , element , attrs ) {
15+
16+ var locals = {
17+ $scope : scope ,
18+ $element : element ,
19+ $attrs : attrs
20+ } ;
21+
22+ element . data ( '$Controller' , $controller ( scope . $eval ( attrs . dynamicController ) , locals ) ) ;
23+ }
24+ } ;
25+ } ] ) ;
26+
27+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments