Giter Site home page Giter Site logo

Comments (7)

hotforfeature avatar hotforfeature commented on July 30, 2024

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 to value="[[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 the input property and onInputChanged events, which are not normally part of the vaadin-grid item model.

from origami.

YodaNinja avatar YodaNinja commented on July 30, 2024

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.

hotforfeature avatar hotforfeature commented on July 30, 2024

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.

YodaNinja avatar YodaNinja commented on July 30, 2024

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.

hotforfeature avatar hotforfeature commented on July 30, 2024

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.

YodaNinja avatar YodaNinja commented on July 30, 2024

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.

hotforfeature avatar hotforfeature commented on July 30, 2024

No problem, glad to have helped :)

from origami.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.