Comments (7)
You're using Angular-style bindings inside of a Polymer template. The bindings are set up once on the template elements, but are lost when vaadin-grid clones the template to instantiate it. You can read more about this problem in the polymer template docs.
TL;DR; add ngNonBindable
to all Polymer <template>
elements to ensure no Angular bindings slip through (and to remind you). All child elements of a <template>
must use Polymer syntax binding.
@Component({
selector: 'my-component',
template: `
<vaadin-grid-column resizable width="9em">
<template class="header" ngNonBindable [polymer]="this">
<vaadin-grid-sorter path="firstName">
<vaadin-grid-filter path="firstName" value="[[input]]">
<div style="display: inline-flex; align-items: center;">
<paper-input no-label-float label="First Name" on-value-changed="onInputChanged"></paper-input>
<iron-icon icon="icons:arrow-upward"></iron-icon>
</div>
</vaadin-grid-filter>
</vaadin-grid-sorter>
</template>
<template ngNonBindable>[[item.firstName]]</template>
</vaadin-grid-column>
`
})
export class MyComponent {
input: string;
onInputChanged(event: CustomEvent) {
this.input = event.detail.value;
}
}
The key things to note:
[ngNonBindable]
on the templates will let you use Polymer's two-way binding syntax{{ }}
, which would normally be replaced with Angular's binding syntax. In this situation you don't use it, so while it's not needed, it's a good habit to get into.[value]="input"
is changed tovalue="[[input]]"
(value-changed)
is changed to Polymer's event binding,on-value-changed
, which takes a function name- The directive
<template [polymer]="this">
is added to the template to set the template's host. This is what allows Polymer to find theinput
property andonInputChanged
events, which are not normally part of the vaadin-grid item model.
from origami.
Thank you! This helped.
However, I'm now getting an error for the <template [polymer]="this">
:
Can't bind to 'polymer' since it isn't a known property of 'template'. (" <vaadin-grid-column resizable width="9em"> <template class="header" ngNonBindable [ERROR ->][polymer]="this"> <vaadin-grid-sorter path="firstName">
Any idea what may be causing this?
from origami.
Sounds like Origami's PolymerModule
is not provided for that component. In your top-most root app NgModule are you importing it?
@NgModule({
imports: [
BrowserModule,
FormsModule,
PolymerModule.forRoot()
],
declarations: [
AppComponent
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
bootstrap: [AppComponent]
})
export class AppModule { }
from origami.
I added that, but it still produces the same error.
I then added it to my submodule, and the error is now resolved!
Thank you!
Now, I'm trying to figure out how to share the root PolymerModule.forRoot()
instead of importing in all the submodules...
from origami.
Are you lazy-loading your submodule or something? If your submodule is imported directly into your main module you don't need to add it to submodules.
If you're lazy loading via the Angular router, I'd suggest creating a SharedModule that imports and exports common dependencies such as Origami. This isn't a problem unique to Origami, that's for every Angular library and dependency, including things like FormsModule
.
Finally, you should not import PolymerModule.forRoot()
in child modules. Just import PolymerModule
without the .forRoot()
invocation. That should only be for the top-most module.
from origami.
Yes!
Just found the comment: // Do not call .forRoot() when importing in child modules
.
So, in my top-most root app NgModule I have:
PolymerModule.forRoot()
And in each of the submodules, I've added just:
PolymerModule
This is working perfectly...
I'll look at your suggestion for making a SharedModule as well for common imports.
Many thanks!
from origami.
No problem, glad to have helped :)
from origami.
Related Issues (20)
- Failed to compile entry-point @codebakery/origami/styles (module as esm5) due to compilation errors HOT 2
- paper-input-container attach causes "Cannot read property 'addEventListener' of null" HOT 1
- Angular 13 @angular/common Could not resolve dependency HOT 3
- Cannot read property 'polyfillWrapFlushCallback' of undefined
- Allow project root, app root, and .bowerrc directories for polymer-webpack-loader HOT 9
- Support for embedded media in Polymer elements ? HOT 2
- Unit Tests HOT 3
- Any way to run this with Angular 6? HOT 5
- Instead of `path-cli`, couldn't we use `ng eject` istead? HOT 4
- Docs: Zone.js doesn't play nice with webcomponents HOT 3
- Polyfill utilities throws "TypeError: Cannot read property 'toLowerCase' of undefined" HOT 7
- Dynamic/defer importing the AppModule makes the app failed to compile HOT 4
- IncludeStylesModule expects RouterModule to be imported. HOT 3
- Update for Angular 7 support HOT 5
- @IncludeStyles does not work on non-root component HOT 13
- Latest version 3.1.1 causes ERROR ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor HOT 4
- routerLink within <template> HOT 1
- Origami prepare command throwing error with Polymer v3.3.1 HOT 2
- Angular 9 and ivy HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from origami.