use of com.vaadin.flow.template.angular.StaticBindingValueProvider in project flow by vaadin.
the class TemplateElementStateProviderTest method testElementAttributes.
@Test
public void testElementAttributes() {
ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setAttribute("a1", new StaticBindingValueProvider("v1")).setAttribute("a2", new StaticBindingValueProvider("v2"));
Element element = createElement(builder);
Assert.assertEquals("v1", element.getAttribute("a1"));
Assert.assertEquals("v2", element.getAttribute("a2"));
Assert.assertEquals(new HashSet<>(Arrays.asList("a1", "a2")), element.getAttributeNames().collect(Collectors.toSet()));
}
use of com.vaadin.flow.template.angular.StaticBindingValueProvider in project flow by vaadin.
the class DefaultElementBuilderFactory method setBinding.
private void setBinding(Attribute attribute, ElementTemplateBuilder builder, Element element) {
String name = attribute.getKey();
if (name.startsWith("(")) {
if (!name.endsWith(")")) {
throw new TemplateParseException("Event listener registration should be in the form (click)='...' but template contains '" + attribute + "'.");
}
String key = extractKey(name, 1);
builder.addEventHandler(key, attribute.getValue());
} else if (name.startsWith("[")) {
if (!name.endsWith("]")) {
throw new TemplateParseException("Property binding should be in the form [property]='value' but template contains '" + attribute + "'.");
}
handlePropertyParsing(attribute, builder, element, name);
} else {
/*
* Regular attribute names in the template, i.e. name not starting
* with [ or (, are used as static attributes on the target element.
*/
builder.setAttribute(name, new StaticBindingValueProvider(attribute.getValue()));
}
}
Aggregations