Created
November 27, 2013 15:14
-
-
Save squeaky-pl/7677343 to your computer and use it in GitHub Desktop.
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
Directive | |
app.directive \component, [\$injector \$compile \$q (injector, compile, q) -> | |
deferred = q.defer! | |
promise = deferred.promise | |
scope: {} | |
restrict: 'A' | |
compile: (element, attrs) -> | |
require [attrs.component] (component) -> | |
deferred.resolve component | |
(scope, element) -> | |
promise.then (component) -> | |
element.html component.template | |
compile(element.contents!)(scope) | |
element.html \Loading... | |
controller: [\$scope (scope) -> | |
promise.then (component) -> | |
injector.invoke component.controller, null, '$scope': scope | |
] | |
] | |
View | |
<h1>Log</h1><div x-component=log/component></div> | |
log/component | |
define [\text!./template.html], (template) -> | |
template: template | |
controller: [\$scope \$rootScope (scope, root) -> | |
scope.logs = [] | |
root.$on \pull.log, (e, log) -> | |
scope.logs.push log | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment