Angular hidden div dynamically unhiding best practices - html

I'm building an Angular application with a login page. The login page contains the following elements:
Login form
Password forgot form
Password forgot acknowledge message
Password reset form (you end up here after clicking the link sent by e-mail)
Loading spinner
At first, the login form should be presented. When you click the forgot my password link, the login form should disappear and the password forgot form should appear in which a user can enter his email address and press a button to request a new password. Next on, the user is presented the password forgot acknowledge message with text stating what is going to happen next.
When the user clicks the link sent by e-mail he is redirected to the login page again and presented with the password reset form where he can enter his desired password.
What I have currently done is written all divs successively in the login.component.html page. By default all are hidden except for the login form using (example) *ngIf="forgotpassword" [#fadeInOutRight]. Then, based on buttons or links clicked on the page dynamically divs fly in and out of the screen using Angular Animations.
I was wondering if this is good practice or if there's any other technique that should be used to dynamically change the content of the page.
Any tips are much appreciated.
Thanks!

You should probably use routing for the purpose you are describing. Have a look at https://angular.io/guide/router
That's at least how I would do it. It has multiple advantages:
Clearly seperates the code into cohesive components that serve one purpose
The users and you can now directly access the routes
You don't have to write the hiding/switching logic, because Angluar already provides that
The clear seperation makes it easier to test

first ngIf does the trick, you can also consider using the [hidden] property. The difference is with ngIf, you create and delete elements from the DOM, while with the [hidden] property you just hide them. But as long as your users will not spam switching from one form to another, I think it's fine using ngIf.
I would recommand splitting your login page in components. For example, one for the login form itself, another one for the password forgot form, etc...
This way, when the user click the forgot password button, you just direct her/him to the corresponding component.
Hope that helps

Related

Show a particular DIV from a previously viewed page

I'm not sure if this is possible (I'm not a coder!) but here goes anyway...
The DIV class for the product name on the following page is "productTitle"
https://www.ultimadisplays.co.uk/Alcohol_Hand_Sanitiser_Gel/?categoryId=2147499177&tab=0&subTab=1
I won't bore you with why but the website is very old and limited however we can put a button on each product page which can link to a form. This form is on a completely separate hosted platform.
Is it therefore possible to take the product name over to the new page with the form on it using the DIV class so that when the form is submitted we will know what product they are interested in rather than they have to write it into the form manually?
Thanks in advance!
You can send whatever data you want between different sites or platforms by sending it in GET or POST request either by refreshing page directly or by using AJAX.
I don't think it's a good option just for a form. But you have this possibility nevertheless.

How to return an image through asmx web service and show in html page

I want to return image(s) through asmx webservice and show them in a html page.
I should not images are located in a folder named by numbers (1.jpg, 2.jpg and etc.) on server and also I should note that I don't want to make and use url for each image because it may cause security issues for me.
I have a textbox in my html page with a submit button and I want to see "1.jpg" in my html page when I insert 1 in textbox and press submit button.
Please help me to play out.
I have a textbox in my html page with a submit button and I want to see "1.jpg" in my html page when I insert 1 in textbox and press submit button.
Simply return the image data from your service along with the appropriate Content-Type header, such as image/jpeg. Then, use JavaScript to create an img element that references your service:
<img src="images.asmx?image=1.jpg" />
I don't want to make and use url for each image because it may cause security issues for me.
I don't know what security issues you're referring to, but just because you can access these images via script doesn't make them secure. Anyone can access them this way unless you take steps to prevent it. It's no different than simply changing the URL.

Facebook, StaticHTML and form summission

This is weird!
I have set up a form using RapidMailer, and on an external site it works fine. (Just to complicate matters, the form is within a <div> as I display a background image, and then use the <div> to position the signup box halfway down the page)
But ...
Put it within an Facebook (Thunderpenny) StaticHTML page, (which I think is <iframe>?) and whilst I can enter name/email, and the submit button shows mouse up/mouse down events, it just won't submit.
I tried adding "pointer-event:auto" to the div so that it was to the fore, but no go. And no good asking the app creator as I doubt I'll get a response. Anyone any ideas? (** I could include page code, but it's 90% links to external js files Rapidmailer sets up)
Is it 'cos I got a <div> within an <iframe>? Do I need to add an <object> to the code somewhere???
It turns out that for some reason, the HTML code cannot find / use the javascripts even with direct URL's. I strongly suspect it's to do with "cross browser" limitations. In otherwords, the StaticHTML <iframe> is on one server, and the HTML code is trying to access javascript on a second server. And as the RapidMailer script is using three scripts direct from jquery.com, it's difficult to know what can be eliminated as they all contain error trapping routines.
In the end, I had to add a direct link to a status update on the Facebook page, and redirect it to the signup form on my blog. I then pinned the post the top. Alas, now for some reason it won't display a graphic with the link, and instead insists on showing the URL itself! Oh well!

jquerymobile - Chrome won't prompt to save password on standard POST submit

Chrome doesn't seem to be consistent regarding when it prompts to save password. Consider the following two processes from my web site...
Go to home page
Click Login (this takes you to Login.php)
Enter a login/password
You're logged in now, but Chrome did not prompt you to save the password
However...
Go to home page
Click Login
Refresh the page
Enter login/password
You're logged in now, and Chrome did prompt to save the password...
What gives? The only difference is hitting "refresh". The code for Login.php is very very simple... essentially:
<form id="LoginForm1" action="Login.php" method="POST">
<input type="text" name="UserName" />
<input type="password" name="Password" />
<input type="submit" value="Login" />
</form>
There's javascript (jquery-1.7.2 and jquery.mobile-1.3.0) on the main page, but not on Login.php. It seems to carry over, though, because the styling of the form on Login.php looks like jquerymobile until the refresh. Can anyone explain this behavior? (And furthermore, why does jquery/jquerymobile inhibit the Save Password feature?)
Thanks in advance... this is my first question asked.
Short answer
The link from my homepage to Login.php needed data-ajax="false" in the a href tag.
After I re-included jquery-mobile to Login.php, the form tag on Login.php also needed data-ajax="false".
 
Long answer
Part 1
After more digging, I found that the normal behavior for jquery-mobile is to "hijack" all a href links and process them through its ajax functionality. This means it was transferring to Login.php as an ajax-style transfer, instead of a standard a href transfer. A standard transfer checks Login.php for its specifically declared javascript include files, but the ajax transfer carried over the javascript includes from the homepage.
However... when you force the browser to only look at Login.php (by clicking refresh) it found that there weren't any javascript includes, and so Chrome looked at the naked page ane dealt with it properly.
 
Part 2
You have to meet several requirements for Chrome to prompt to save a password. Among them include:
You have to use a form element
You have to use a submit, not a button
The submit has to be a real submit. (If you override the submit functionality with some javascript/Ajax... it (probably) won't prompt to save a password.)
The form has to be visible when the page loads.
 
When working with jquery-mobile, 3 and 4 can trip you up.
 
With respect to 3...
jquery-mobile automatically hijacks the form submit process, the way it does with links... so it's necessary to add data-ajax="false" to the form element to prevent it from doing that.
 
With respect to 4...
The first version of my website had a login panel on the home page where the login button revealed the panel from "underneath" the page. This method would not prompt for a password until I forced the panel to be visible on page load.
Since I didn't want the login panel always to be visible on the home page, I decided to use a separate login page (Login.php). However jquery-mobile's inherent way of treating links to separate pages is to hijack them with its ajax functionality... which the browser interprets as staying on the same page. So for Chrome, navigating to Login.php was the same as using a hidden panel... because Chrome interpreted both requests as staying on the home page... and in either case, the form element was not visible when the page originally loaded.

page redirect like in facebook

In facebook, if any photo of yours is tagged then you got informed in your mail.When you press link on the mail then
the page with tagged photo will be open if already logged in facebook
log in and will reach to tagged photo if not already logged in.
I am making pure html,jquery in frontend and asp.net services as backend. How can i achieve it. Suppose,
there are 3 page in my website: first-login_page.html, second-second_page.html, third-third_page.html.
Now the mail contains link to third page.
I have open third_page directly if already logged in.
I have to go to first page(login page) if not logged in. Then user enter username and password and press enter then will go to third page.
Can you give some idea on how can I do it.
On 2nd & 3rd page ,use one Hidden field. Suppose some one login then store some Token Key or anything in Hidden field.... Now someone come via link which is sent in email... By javascript/jQuery check that Hidden field is NULL or not, also set logic... Check if Hidden field have valid value or not. From this you can check if user is already Logged In or not.... Suppose he is not login then redirect on login page else go ahead....
Hope you are familiar with code syntax..Enjoy
On the third_page, you check if the user has logged in or not
if the user hasn't logged in, redirect the user to login page