Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

allow to pass attributes from parent component via ngOutlet directive #406

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/ngOutlet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function createOutlet($q, $animate) {
function Outlet(router, scope, element, controller, $transclude) {
function Outlet(router, scope, element, controller, $transclude, attrs) {
this.router = router;
this.scope = scope;
this.element = element;
Expand Down Expand Up @@ -69,7 +69,14 @@ function createOutlet($q, $animate) {
if (typeof componentName !== 'string') {
throw new Error('Component is not a string for ' + instruction.urlPath);
}
this.controller.$$template = '<' + dashCase(componentName) + ' $router="::$$router"></' +
var passedAttributes = " ";
for (var key in attrs) {
// TODO rewrite 'if' to pass only 'bindings' attributes of current component
if (key && key[0] !== '$' && key != 'class' && key != 'id') {
passedAttributes += key + '="' + attrs[key] + '"';
}
}
this.controller.$$template = '<' + dashCase(componentName) + passedAttributes + ' $router="::$$router"></' +
dashCase(componentName) + '>';
this.controller.$$router = this.router.childRouter(instruction.componentType);
this.controller.$$outlet = this;
Expand Down Expand Up @@ -115,7 +122,7 @@ exports.ngOutletDirective = function($animate, $q, $rootRouter) {
var parentCtrl = ctrls[0], myCtrl = ctrls[1],
router = (parentCtrl && parentCtrl.$$router) || rootRouter;
myCtrl.$$currentComponent = null;
router.registerPrimaryOutlet(new Outlet(router, scope, element, myCtrl, $transclude));
router.registerPrimaryOutlet(new Outlet(router, scope, element, myCtrl, $transclude, attrs));
},
controller: function() {},
controllerAs: '$$ngOutlet'
Expand Down Expand Up @@ -160,4 +167,4 @@ exports.routerTriggerDirective = function($q) {

function dashCase(str) {
return str.replace(/[A-Z]/g, function(match) { return '-' + match.toLowerCase(); });
}
}