In AngularDart I have a view.
https://angulardart.org/tutorial/08-ch06-view.html
'demo_table': ngRoute(
path: '/demo/table',
view: 'views/demotable.html'
),
On the view I have two components.
<component1 view-string="Component 1"></component1>
<component2 view-string="Component 2"></component1>
I would like view-string to be an instance of a string which may be changed by either component1 or component2. The changes should be reflected in the display of the string in the component.
I don't see how to keep a string within this view, as this view is not a component. Usually I would use a "{{someString}}" in the view-string if this view was really a component with a dart object.
Greg Sherman's answer using MySharedClass is correct, but is missing the @Injectable() annotation. You'll need something like this:
One way to solve the problem and still use components as opposed to controllers is to introduce a class that contains your shared data. In fact, this also works exactly the same with controllers, but that's a moot point because controllers seem to be going away as Randal mentioned.
(Please pardon any typos or errors - I'm typing right into the text editor, so this may not compile.)
Step 1: Introduce a shared class, annotate it as Injectable:
Step 2: Make sure that that Angular can inject the class by telling Angular about it:
Step 3: Now add the shared class to your components' constructors. Angular will automatically inject an instance as long as you declare a requirement for it:
And now you have access to your shared class between the two (or more) components as you see fit.
(Modified per Wilson Yeung to add Injectable() annotation)
The solution I found is to use a controller, in my view I can have {{ctrl.test}} to view the controllers string.
The controller.
In the view, add the controller.