I am developing an Ember app and it is really great. But I have a annoying problem I can not solve. I use routing in my app and two diffent controllers with their own views. If I try to use a binding property from the first controller to the second one, that property is not reflected in the second view. In a short way I have something like this:
router = Em.Router.extend({.....});
App = Em.Application.create({
Router: router,
FirstCtrl: Em.Controller.extend({x:'ABC'}),
FirstView: Em.View.extend({...}),
SecondCtrl: Em.Controller.extend({xBinding:'Em.App.router.firstCtrl.x', y:'123'}),
SecondView: Em.View.extend({...}),
});
App.initialize();
Em.App = App;
If in the template for the second view I have something like this:
Binding property: {{x}}
Property with no binding: {{y}}
'ABC' is not shown in the view but there is no such problem with '123'.
In my browser I can access that property from Javascript console with Em.App.router.firstCtrl.x but Em.App.router.secondCtrl.x returns undefined.
So, my question is Why can't I access that property? How should I write that binding?
Thanks in advance for your help
I don't think Em at the beginning of binding is required, Try this..
SecondCtrl: Em.Controller.extend({xBinding:'App.router.firstCtrl.x', y:'123'}),
Well summing up the comments:
All the controllers defined in ember must end with Controller while routing, for example if you call router.get('applicationController').connectOutlets('home') its corresponding controller shall be App.HomeController or App.homeController
while binding use 'App.router.yourController.yourProperty' instead of 'Em.App.router.yourController.yourProperty'
We can also use connectControllers in order access properties across controllers if you want to avoid global bindings
Related
I've this two lines on all the action() in the controller so I want to move it to init() so it will get called each time. It doesn't work so I tried __construct and it won't work as it says "PHP Fatal error: Uncaught Error: Call to a member function get() on null"
Maybe that can be done in factory and you still call getServiceLocator in factory class? If I can do it within controller that will be even better as that's less step to do and is that possible to do it in controller so every action will have that?
$view_helper = $this->getServiceLocator()->get('viewhelpermanager');
$view_helper->get('headScript')->appendFile(....);
Only two solutions exist:
You can do an abstract controller, and use the viewhelpermanager as dependency in your constructor. This means you will need to pass the viewhelpermanager in all the subclasses factories and not forget to call the parent construct and so on when creating the object.
You can use a delegator in the service manager and an abstract controller that contains a setViewHelperManager method and a viewhelpermanager (or worst, a trait :) and a ViewHelperManagerAwareInterface and an initializer), and do a "soft dependency", but that's a wrong way to do things in terms of maintenance (code readability).
Why don't you write your own view helper and make that include the js file(s). You can then use this in all the view.phtml files that require these files. If you need to change/add/remove js files then just do this in your view helper, obviously this change will reflect in all your views that use it.
This keeps the view stuff away from your controller.
Hope this helps.
I am using angular ui grid. At first I implemented this in a controller and it works fine after all my customization. As I am using multiple grids I cannot write a long controller each time. So, I converted it to factory. I kept the common function in factory and column definition and data in controller. Now when I use this factory in more than 1 controllers, the last controller is overriding all others.
1) Is it correct to make this grid in a factory?
2) If yes how do I overcome this problem?
3) By using factory for this grid, my gridObj.gridApi.pagination.on is throwing error(gridObj is the singleton object that I am returning).
Any suggestion is welcome. Thanks a lot in advance.
You should use a Directive instead. Factories create a single Instant (see Angular Provider Documentation and wont create a private scope, which you need to not override your data.
Note: All services in Angular are singletons.
But Directives provide a private scope and create new instances every time they are called in HTML if you want them to.
//directive
scope: { // this option creates isolated scopes
something : '=',
},
I created a Plunkr showcasing a possible setup. For some more written details please see my answer from few days ago.
Your HTML might look like this afterwards
<my-grid options="all.firstOptions" class="grid"></my-grid>
Where my-grid is your directive and options="" are your special settings (and whatever else you wish to use in the directive). In your directive you declare the default settings and merge them with the special ones.
scope.gridOptions = {
data: scope.options.data, //private scoped from options : '=',
columnDefs: scope.options.colDef || defaultColDef, // optional setting or default setting
// ... some more default data
};
If you have any specific questions, let me know.
I am refactoring an MVC 3 application, and moved a set of similar items into a partial view so I can keep that template DRY. Since the pieces don't all have the exact same properties, I am creating anonymous types like this:
var model1 = new { Description = "description 1", Message = "message 1" }
and passing them to the partial view like so:
#Html.Partial("_Partial", model1)
The partial view is then attempting to render certain blocks based on existence of a specific property, i.e.
#if (Model.Description != null)
{
#Model.Description
}
My issue is that even though I can see and navigate the Model object in the watch window during execution, I get a RuntimeBinderException in the if test that states 'object' does not contain a definition for 'ShowApplied'. I can obtain the values through reflection by calling (Model.GetType().GetProperty("ShowApplied").GetValue(Model)), but would much rather use the format shown in my code sample. I have been unable to find a clean solution...
How can I pass an anonymously-typed object to a partial view and access its properties directly? I feel like there is something simple I'm missing...
Why am I able to see the Model properties while debugging, but not access them from code?
EDIT
I am specifying #model dynamic.
Using an interface requires creating non-anonymous types because, as this answer explains,
An anonymous type cannot be cast to any interface or type except for object.
Insights from the comments (thank you) imply I have 2 options, since (as the answer to the linked question points out),
Anonymous types are internal, so their properties can't be seen outside their defining assembly.
and therefore are inaccessible to the Razor binding engine.
Use #Html.DisplayFor("amount") and deal with not having IntelliSense, reference lookups, etc.
Create classes that implement a common interface and bind my partial view to that interface.
Think of the following:
I've got a table data grid webcomponent and another component providing a data feed. In the applications main acting as kind of controller, i'd like to wire and setup those two components. Therefore i need a reference to underlying table grid instance Dart class and call methods on the "Component API' (to provide the table grid's tablemodel with data).
How do I access the Dart Class instance of a webcomponent instance from outside ?
Probably I missed something fundamental or are polymer webcomponents meant to interact only using databinding and stringy attributes stuff ?
Follow up: Found it !!
RLTable table = querySelector("#apptable").xtag;
does the job
As zoechi pointed out, xtag is not necessary.
var component = $['myComp'];
var componentXtag = $['myComp'].xtag;
print(component == componentXtag);
prints true. Therefore both
component.method()
componentXtag.method()
work fine
You don't need xtag. Some weeks/months ago this was a workaround until the final solution was landed.
I called a method from another controller using this
AnotherController oriCon = new AnotherController();
oriCon.ApproveOperation(formCollection, ref responseMsg);
Now, inside the ApproveOperation method, I called the session variable like this
int activeUser = (int)HttpContext.Session["user"];
But its giving me error; null value
I've asked before in forums.asp.net, someone told me to use
HttpContext.Current.Session
But I can't use that, there is no Current property in my HttpContext. Did I have no Current property because I'm using MVC 1.0 framework 3.5. Maybe the guy who answered me using MVC 2.0 framework 4.0?
Can anyone give me light on this?
What do you mean "called a method from another controller"?
I don't think you should be doing that. If its a common function that is used by two different controllers then put it in a separate class and then use it. You should be able to access Session from all your controller.