在angularjs应用程序中可以使用event.preventDefault()吗?

时间:2020-12-15 22:59:50

In my ionic application while page load each time it's loading the login page then it's coming to profile page . I think if this works i can can use it in profile controller so that each time i can see the current page which is getting refresh.

在我的ionic应用程序中,当页面每次加载登录页面时它就会进入配置文件页面。我想如果这个可行的话,我可以在配置文件控制器中使用它这样每次我都能看到正在刷新的当前页面。

Can any body help me out to achieve this?

有谁能帮我实现这个目标吗?

Again when i am navigating to each page using $state.go("app.profile") or $state.go("app.signup"), Each time it's loading login.html as a splash screen & later it's navigating to the requested page.

同样,当我使用$state.go(“app.profile”)或$state.go(“app.signup”)导航到每个页面时,每次加载login时都是如此。html作为一个闪屏&稍后它导航到请求的页面。

My requirement is if I refresh the profile page or signup page it should only reload the current page not login page.

我的要求是,如果我刷新配置文件页面或注册页面,它应该只重新加载当前页面而不是登录页面。

Any help would be appreciated.

如有任何帮助,我们将不胜感激。

3 个解决方案

#1


1  

You just need to pass the event to the function and handle it from there, it's the clean and best way doing it:

你只需要将事件传递给函数并从那里处理它,这是一个干净的最好的方法:

in your view(html):

在你的观点(html):

<button (click)="clicked($event)">click</button>

and in your Javascript (Typescript):

在你的Javascript(打字稿):

clicked(e) {
  e.preventDefault();
  //then do whatever you should do here
}

#2


1  

Thanks All ,

谢谢,

My problem got solved . I made two changes in my app. used preventDefault() as required . And i changed the $stateProvider to $routeProvider. inside app.config i put the below code

我的问题解决了。我在应用程序中做了两个更改。我将$stateProvider改为$routeProvider。在app.config中,我将下面的代码放入其中。

  $routeProvider
         .when("/app", {
            // controller: AppCtrl,
        templateUrl: 'templates/menu.html'
    })       .when("/signup", {
        //   controller: SignupCtrl,
        templateUrl: 'templates/signup.html'
    })       .when("/profile", {
       //  controller: ProfileCtrl,
        templateUrl: 'templates/profile.html'
    });

#3


0  

You can just return false in the event handler

您可以在事件处理程序中返回false

(click)="onClick($event);false"

or

(click)="onClick($event)"
onClick(event) {
  event.preventDefault();
  // or
  return false;
}

#1


1  

You just need to pass the event to the function and handle it from there, it's the clean and best way doing it:

你只需要将事件传递给函数并从那里处理它,这是一个干净的最好的方法:

in your view(html):

在你的观点(html):

<button (click)="clicked($event)">click</button>

and in your Javascript (Typescript):

在你的Javascript(打字稿):

clicked(e) {
  e.preventDefault();
  //then do whatever you should do here
}

#2


1  

Thanks All ,

谢谢,

My problem got solved . I made two changes in my app. used preventDefault() as required . And i changed the $stateProvider to $routeProvider. inside app.config i put the below code

我的问题解决了。我在应用程序中做了两个更改。我将$stateProvider改为$routeProvider。在app.config中,我将下面的代码放入其中。

  $routeProvider
         .when("/app", {
            // controller: AppCtrl,
        templateUrl: 'templates/menu.html'
    })       .when("/signup", {
        //   controller: SignupCtrl,
        templateUrl: 'templates/signup.html'
    })       .when("/profile", {
       //  controller: ProfileCtrl,
        templateUrl: 'templates/profile.html'
    });

#3


0  

You can just return false in the event handler

您可以在事件处理程序中返回false

(click)="onClick($event);false"

or

(click)="onClick($event)"
onClick(event) {
  event.preventDefault();
  // or
  return false;
}