angular js页面传递参数

var myapp=angular.module("myApp",["ngRoute","ui.router"]);
myapp.controller("FCtrl",function($scope,$state){
     $scope.toSecound=function(name){
           $scope.go("secound",{"name":name});
    }
});
myapp.controller("SCtrl",function($scope,$state,$stateParams){
    
           $scope.name=$stateParams.name;
    
});
myapp.config(function($stateProvider, $urlRouterProvider){
   $stateProvider
   .state("first",{
        url:"/first",
    templateUrl:"servicing/first.html",
    controller:"FCtrl" 
    })
    .state("first",{
        url:"/secound",
    templateUrl:"servicing/secound.html",
    controller:"SCtrl" 
    })
}

 

转载于:https://www.cnblogs.com/xiudu/p/7504063.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用Angular的内置Router模块来导航到新页面,然后使用JavaScript的window.print()函数来打印HTML页面。以下是示例代码: 在您的组件中,导入Router和ActivatedRoute模块: ``` import { Router, ActivatedRoute } from '@angular/router'; ``` 在构造函数中注入这些模块: ``` constructor(private router: Router, private route: ActivatedRoute) { } ``` 在需要打印HTML页面的函数中,使用Router模块的navigateByUrl方法导航到新页面,并在导航完成后调用window.print()函数: ``` printPage() { const pageUrl = window.location.href; const newUrl = pageUrl.split('?')[0] + '/print'; // 添加“/print”路径 this.router.navigateByUrl(newUrl).then(() => { window.print(); }); } ``` 在新页面的组件中,使用ActivatedRoute模块获取HTML页面的内容并显示在页面上: ``` import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-print', template: '<div [innerHTML]="htmlContent"></div>' }) export class PrintComponent implements OnInit { htmlContent: string; constructor(private route: ActivatedRoute) { } ngOnInit() { this.htmlContent = this.route.snapshot.queryParamMap.get('html'); } } ``` 在新页面的路由配置中,添加一个路由来匹配“/print”路径,并将HTML内容作为查询参数传递: ``` const routes: Routes = [ { path: 'print', component: PrintComponent } ]; // 在导航时传递HTML内容 const queryParams = { html: '<h1>要打印的HTML内容</h1>' }; this.router.navigate(['/print'], { queryParams }); ``` 请注意,这只是一个简单的示例,您需要根据自己的需求进行修改和改进。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值