Does there exists a build in function that keeps on reloading the whole component until a boolean gets true. Bacause now before I can get some data I need to wait until a user has clicked a button in another component. But there is no relationship between those 2 components.
Does someone knows a way how to do this.
thx!
you can make use of Event Emitters in components to share information so that you need not wait for a user dependent action . Also make use of Service classes in order to pass information between components.
https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service
Also if you are getting information from a http call try and use observables or promises and then use ngIf or a elvus operator to get info into the component.
More on Angular Concepts https://rahulrsingh09.github.io/AngularConcepts/
I solved it by using a service where is create a subject/observable.
Check the link:
https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service
check the: Parent and children communicate via a service
Related
I wish to add this design as a time slider in my dashboard.
Has anyone ever designed this using React, HTML? Any help is appreciated.
If those circles, lines are based on your returned json data, it is quite straightforward with React / Redux. You can follow the steps:
You need to add event listeners on your timeline either click or mouseover
Define the state variable mapData in the constructor
trigger the event and retrieve different data via http request
make sure you call setState() with the new data and bind them into your state variables
Bind the state variable into the render() elements and you will see the change.
Hopefully it can help you out.
I'm using redux and es6. I want to dispatch an action before components will mount. The problem is that with redux newest syntaxis componentWillMount doesn't exists any more. So... where should i dispatch this action.
My case: I have a component that needs user's info (such as name, for example). I need to get the user's name before that component mounts.
thanks,
Connect your component to a field in your state, let's call it "name". When the component renders, make sure it checks if name is not empty; if it is then it renders it, if not then it renders nothing.
In the componentDidMount, fire your dispatch as normal - this in turn will reduce and end up changing the value of "name" in your state. This will cause a re-render and will then show properly.
componentWillMount only exists server side, so it is usually not the best idea to dispatch actions from it, as if you just had your client side code, they wouldn't work.
I created one controller SlideController for manage the slide on my website.
But In the SiteController I just want to load some action in the SlideController.
Is it possible or not? If it's possible ,how can I?
Yes, it is possible.
The proper way I think, is to create yii2\base\Action subclasses which contain common actions shared by different controller.
As a reference on how to write Action and how controller links up it, you can read the source code here - https://github.com/yiisoft/yii2/tree/master/framework/rest
You can use this for your need:
https://stackoverflow.com/a/30432980/748156
In your case, in SiteController, set it like:
Yii::$app->runAction('slide/action', ['param1'=>'value1', 'param2'=>'value2']);
I am trying to make a generic connectivity class in my Windows Phone 8 app. This class should be used whenever i need to send a POST request to the service.
In a particular use case i need to call the service, display the response and navigate the user away from the current page.
I am able to successfully achieve the first 2 objectives using the connectivity class. This is because the connectivity class is not part of the UI. So is there a way the GetResponseCallBack method can inform the calling method that it has received the response and then i can navigate the user?
Hope i was able to ask my question clearly.
Thanks!
I have managed to find a work-around for now. Not sure if it is the right way to get the response of the async task. But i am sharing it for the benefit for others who may be facing similar issue.
What i have done is, i have defined the GetResponseCallBack as a public method in the class calling the async task method. Later i pass the same GetResponseCallBack as a parameter to the beginGetResponse method in the GetRequestStreamCallBack method.
This way i am able to bring the control flow back to the phoneApplicationPage after the asyncTask executes, thus allowing me to handle some events on the UI thread.
Hope it helps!
I'm After several days learning angularJS through converting my standart JS app to a ng one.
I was wondering about this simple scenario:
I have a global function called fb_connect(),
it can be used from any page (or any controller if you like) to make a facebook-based login.
This function makes a simple http call and receives a JSON object contain data to move on (display a pop up, login, etc...)
I read that I can define a Factory or a Service for my app and use it in any controller, which works fine.
So, I created a fb_connect factory function.
The problem is that now, in every page (every controller), I have to define that fb_connect in the constructor of every controller - for example :
function welcome($scope,fb_connect){});
What is the proper way to do this kind of actions using Angular without having to define these functions each and every time in every controller?
Thanks
Setting up factories and services is all part of the dependency injection system of Angular. Using that system is great when you need to create things that depend on other injected things. It's a big tree of dependencies. It's also nice for creating singletons, such that everywhere in your code end up using the same instance of some object.
It sounds to me like neither of these benefits apply in your case. I'd suggest just not using Angular's DI for it. You have some function defined globally, just call it directly and skip the DI. There's nothing wrong with that.
Of course you say it makes an Ajax call, so doesn't depend on the Angular $http service?
Your two options are:
Declare the function on the $rootScope
Inject it as a service
My advice is to go with making it a service. The whole purpose of services is explained in the Angular.js docs, just like this quote:
Angular services are singletons that carry out specific tasks common to web apps... To use an Angular service, you identify it as a dependency for the dependent (a controller, or another service) that depends on the service.
As you mentioned in your question, you'd prefer to not define the service in every controller you wish to use it in. With $rootScope you'll be injecting that also in every controller. So really it's a question of which you prefer, although to answer your question, the proper way of using a factory or service is to inject it into the controller you wish to use it in.
You can always put it in the $rootScope
myApp.run(function($rootScope, fb_connect){
$rootScope.welcome = function(){
};
});