-
Notifications
You must be signed in to change notification settings - Fork 27.5k
.component template function not accepting annotations #13645
Comments
This is coming in 1.5.0 |
Is there a workaround that we can use until then? Manual injection or something? Or even copying the relevant parts of 1.5.0? I've been using Todd Motto's polyfill along with |
@karlhorky, it sounds more like an issue for https://github.com/toddmotto/angular-component. |
Okay thanks @gkalpak, I've opened toddmotto/angular-component#11 |
Anyone using the component() polyfill, I've added support for Array dependency annotation under release This allows for: // Array annotations with minification
template: ['$element', '$attrs', function template(a, b) {
console.log(a, b); // $element, $attrs
return [
'<div class="counter">',
'<p>Counter component</p>',
'<input type="text" ng-model="counter.count">',
'<button type="button" ng-click="counter.decrement();">-</button>',
'<button type="button" ng-click="counter.increment();">+</button>',
'</div>'
].join('');
}] // No annotations with automated minification (see source code `isArray` ternary + annotations)
template: function template(a, b) {
console.log(a, b); // $element, $attrs
return [
'<div class="counter">',
'<p>Counter component</p>',
'<input type="text" ng-model="counter.count">',
'<button type="button" ng-click="counter.decrement();">-</button>',
'<button type="button" ng-click="counter.increment();">+</button>',
'</div>'
].join('');
} // Basic template String
template: [
'<div class="counter">',
'<p>Counter component</p>',
'<input type="text" ng-model="counter.count">',
'<button type="button" ng-click="counter.decrement();">-</button>',
'<button type="button" ng-click="counter.increment();">+</button>',
'</div>'
].join('') |
@petebacondarwin Note on minification against this: In the // works
link($scope) {}
// also works
link(scope) {} I've added this same behaviour to the component() polyfill here to automatically annotate, would this be worth aligning in the Angular core as well? ... Assuming you need to declare Small comments below: function makeInjectable(fn) {
var isArray = angular.isArray(fn);
if (angular.isFunction(fn) || isArray) {
return function (tElement, tAttrs) {
// isArray check, annotates the function if it's a function, or leaves as DI Array syntax
return $injector.invoke((isArray ? fn : [
'$element',
'$attrs',
fn
]), this, {
$element: tElement,
$attrs: tAttrs
});
};
} else {
return fn;
}
} This allows you to: template: function(a, b) {
console.log(a, b); // $element, $attrs
} |
@toddmotto thanks for the idea but I am concerned that mixing injected and non-injected APIs is too dangerous. |
Given a component:
The controller works, however the template doesn't accept the annotations and returns a string.
The text was updated successfully, but these errors were encountered: