0
I wanted to put a CSS animation while the site is being requested on the server. So I found this code with Angular.
app.config(['$httpProvider', function ($httpProvider) {
// Criando um interceptador de chamadas http.
// O '$q' é um serviço que permite monitoração de chamadas assincronas através de 'promisses' que provem callbacks de funcoes.
// $rootScope é o escopo de maior hierarquia em toda aplicação, e pode ser acessado de qualquer nivel
var myHttpInterceptor = ['$q', '$rootScope', '$window', '$templateCache', 'srvMsgBus', function ($q, $rootScope, $window, $templateCache, srvMsgBus) {
return {
// O 'request' ocorre sempre que uma chamada http for iniciada
'request': function (request) {
// $emit envia um evento para todos os controlers 'filhos' do controle que o está executando.
// Este evento pode ser interceptado por outros controllers e serve como meio de comunicação entre eles.
// Como o $rootScope é o 'pai' de todo e qualquer outro controller, quando ele emite um $emit todos podem interceptar este sinal.
$rootScope.emit('loading-started');
In the head
<script src="staff/app.js"></script>
In the body
:
<div dir-carregando></div>
But when I see the result this error appears on the console:
Failed to load with source "https://ourladyagd.com/components.js”.
Referenceerror: app is not defined[Learn More] app.js:1:1
Typeerror: i is Undefined[Learn More] bootstrap.min.js:6:2745
That code only fires an event, it doesn’t do anything related to displaying something visual. If you just want to display a Please Wait, the most imple way is to put it in your html template and hide it while the loading is not happening, for example with a *ngIf="loading"
– Sérgio S. Filho
If you really want to use this example code you need to put the dir-loading component code here
– Sérgio S. Filho
The dir-loading by what I understood when I researched I put in the first line of the body
– Moises Moraes
Even though he has a request to the app.js file in the head I have to put in the html structure itself?
– Moises Moraes
@Sérgios.Filho You have some other way of doing this than by angle?
– Moises Moraes
can only tell if you show the code
– Sérgio S. Filho
if vc is using angular, the ideal is not to mix the way to do with jquery nor the way to do with pure javascript but to follow the angular pattern
– Sérgio S. Filho
I know more of jquery than angula but on the net I did not find with jquery so I did this test.
– Moises Moraes
With jquery, before you make your ajax request, you adjust the visibility of Please Wait to appear on the screen. Then, when the ajax callback returns, you adjust the visibility or display to hide the Please Wait
– Sérgio S. Filho
@Son Face I’m still new in js. Can you show how? What I know I can’t imagine what you said.
– Moises Moraes
To use this feature, your solution must contain an angular application. Please see how the framework works, without this there is no way to make it work in your solution. https://angularjs.org/
– LeandroLuk
@Moisesmoraes, I edited to make the functional example. This script makes an ajax request to any server I found on google and displays a Wait Please while the answer does not arrive...
– Sérgio S. Filho