I defined an angular.dart component like this:
@NgComponent(
selector: 'dartcomp',
templateUrl: 'dartComp.html',
publishAs: 'ctrl',
map: const
{
'val' : '@val'
}
)
class DartComp
{
String val;
calc(a,b) =>a+b;
}
the usage in the HTML is:
<dartcomp id="dc"></dartcomp>
How to access angular.dart component´s attribute val or method calc() from the main dart
a call to the component like
querySelector("#dc").val = "Frank";
throw:
Class 'UnknownElement' has no instance setter 'val='.
NoSuchMethodError : method not found: 'val='
Receiver: Instance of 'UnknownElement'
Arguments: ["Frank"]
What´s the mistake?
Accessing attributes like class properties works in Polymer but not in Angular.Dart. You have to use the Elements default method
.attributes['attrName'] = value
Maybe there is a better way I'm not aware of, but this way should work at any rate.
workaround for calling methods on Angular components/controllers
Example is also available here: GitHub BWU-Dart Playground
This is the best idea I come up with. Maybe someone of the AngularDart creators knows a better solution. (I also couldn't find a straight forward solution for AngularJS)
EventBus
index.dart with MyComponent and main()
index.html
I tried a different approach.
In a static map in the component I store the instances of the components, so that I can access the component later in the main.dart
the components html:
In the index.html I put 2 of the components
In the main.dart I try to change the val attribute of component dc1
but in the browser I can't see change. Is there a way to solve the problem like this?