Angular 2打开一个静态页面(Angular 2 opening a static page)
我有角度2项目。 我想在新窗口中打开服务器上可用的静态帮助文件。 我试过window.open(help/index.html) 。 它导航到页面但引发有关未找到路线的错误。 我也尝试在角度区域之外运行上面的代码,但没有任何区别。 我怀疑浏览器位置更改角度在下一个更改检测周期中检测到它并尝试路由到该URL。 可以做些什么来实现这一目标。
I have angular 2 project. I want to open static help files available on server in new window. I tried window.open(help/index.html). It navigates to the page but throws error about route not found. I have also tried to run above code outside angular zone but makes no difference. I suspect as browser location changes angular detects it in next change detection cycle and try to route to that URL. What could be done to achieve this.
原文:https://stackoverflow.com/questions/37858849
更新时间:2020-02-22 19:51
最满意答案
您可以尝试利用window.open()方法的name参数,该参数等效于锚标记中的target属性。
window.open("help/index.html", "_blank");
You could try and leverage the name parameter of the window.open() method which is the equivalent of the target attribute in anchor tags.
window.open("help/index.html", "_blank");
working Plunker example
相关问答
就像是 onclick="window.open('default.aspx','','height=300,width:220,scrollbars=yes,resizable=yes,top=0,left=0,status=yes');"
something like onclick="window.open('default.aspx','','height=300,width:220,scrollbars=yes,resizable=yes,top=0,left=0,status=y
...
您可以将express配置为始终提供index.html,无论这个url是什么,这应该允许您通过外部链接访问您的路由: // all routes lead to to index.html
let router = express.Router();
router.get('*', (req, res) => {
res.sendFile(path.join(DIR, 'index.html'));
});
this.express.use('*', router);
You can c
...
我做了两件事就能让这个工作起来: 使用$ scope作为“posts”var: 替换这个: app.controller('HomeController', function($scope){
this.posts = feedback;
});
有了这个: app.controller('HomeController', function($scope){
$scope.posts = feedback;
});
下一步 - 从ng-repeat中删除“home”:
...
有两种方法 初始演示完成后,添加一个提示按钮(它是intro.js中的功能)并在用户单击提示后重新启动演示 使用编程方式添加步骤。 首先显示2个步骤,让用户提交表格并加载控制器。 再次重启introjs there are 2 ways once initial demo is complete, add a hint button (it is feature in intro.js) and restart demo once user click hint use programmatic
...
您想要一种获取用户语言代码的方法。 有了这些,你打算把部分语言代码作为名称的一部分。 Angular translate模块有两种感兴趣的服务方法: $translate.use()返回用户的活动语言。 不幸的是,如果在语言加载到页面之前调用服务方法,则可能会为空。 $translate.proposedLanguage()返回“预期语言” - 表示您将调用$translate.use() ,但即使语言未加载,此调用也会成功。 拥有这个语言代码列表,您可以使用它们为您打算支持的语言创建部分语言。
...
从我所知道的情况来看,可用的各种框架有几种材料设计实现( https://material.io/guidelines/ )。 以下可以在静态html页面上使用,而不需要像Angular 2这样的全能框架: https://elements.polymer-project.org/elements/paper-material http://mdbootstrap.com/ http://materializecss.com/ ...仅举几个。 我们决定的是Polymer的实现。 这是因为聚合物语
...
我并没有完全意识到你试图达到的确切目标,但是在动态版本中,你设置了数据目标href="#collapseInnerTwo"并在href="#collapseInnerTwo" id中尝试评估一些表达式 - [id]="'collapseInnerTwo' + group?.CAMD_PRGRP_DESC" 这些永远不会匹配,永远不会崩溃。 如果你改变了 [id]="'collapseInnerTwo' + group?.CAMD_PRGRP_DESC" 至 id="collapseInnerTwo
...
你可以使用延迟加载。 基本的想法是为你所有的静态页面创建一个模块。 这将是理想的方式。 直到打电话才会下载它们。 export const routes: Routes = [
...
{ path: 'pages', loadChildren: './pages/pages.module#PagesModule' },
...
];
导入如下: RouterModule.forChild(routes)
哪里PagesModule是您的模块名称被延迟加载。 FYI:
...
您可以尝试利用window.open()方法的name参数,该参数等效于锚标记中的target属性。 window.open("help/index.html", "_blank");
工作Plunker的例子 You could try and leverage the name parameter of the window.open() method which is the equivalent of the target attribute in anchor tags. window
...
我之前遇到过这个问题,我认为它是同样的情况: 如果您使用的是Nginx Web服务器,请确保您有正确的规则将任何URL重定向到index.html,例如: location / {
# try_files $uri @rewrite;
try_files $uri /index.html?$query_string;
}
对于Apache我没有真正测试它,但我认为它是相同的情况。 I faced this issue before and i think its the same
...