我试图找出为什么我的角度2应用程序在IE 11中运行时显示正在加载...
根据某人的建议,我尝试过这个有关堆栈溢出的人,在Chrome和IE 11上发布.在Chrome上工作正常,但在IE 11上失败.同样的错误,坚持说"正在加载..."
吸虫是:https://plnkr.co/edit/6zVFbrH5yohwc714gBbk ? p = preview
<!DOCTYPE html>
<html>
<head>
<script>document.write('<base href="' + document.location + '" />');</script>
<title>Router Sample</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.34.2/es6-shim.min.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.1/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/tools/system.js"></script>
<script src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.1/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.1/angular2.dev.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.1/http.dev.js"></script>
<script>
System.config({
transpiler: 'typescript',
typescriptOptions: { emitDecoratorMetadata: true },
packages: {'src': {defaultExtension: 'ts'}}
});
System.import('src/boot')
.then(null, console.error.bind(console));
</script>
</head>
<body>
<my-app>loading...</my-app>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
任何人都知道为什么IE 11无法运行角度2应用程序?
谢谢!
我们有一个企业应用程序,它为客户端使用Angular 2.我们每个客户都有自己独特的网址,例如:https://our.app.com/customer-one和https://our.app.com/customer-two.目前我们可以<base href...>动态设置document.location.所以用户点击https://our.app.com/customer-two并<base href...>设置为/customer-two......完美!
问题是,如果用户是例如,https://our.app.com/customer-two/another-page并且他们刷新页面或尝试直接点击该URL,则<base href...>设置为get /customer-two/another-page并且找不到资源.
我们尝试了以下无济于事:
<!doctype html>
<html>
<head>
<script type='text/javascript'>
var base = document.location.pathname.split('/')[1];
document.write('<base href="/' + base + '" />');
</script>
...
Run Code Online (Sandbox Code Playgroud)
不幸的是,我们的想法很新鲜.任何帮助都会很棒.
我只是想知道,有什么区别
<script>
Run Code Online (Sandbox Code Playgroud)
和
<script type = 'text/javascript'>
Run Code Online (Sandbox Code Playgroud)
不同的网络服务器有什么不同?
例如,(我知道从w3schools提供链接是不正确的,但是看看)
http://www.w3schools.com/js/tryit.asp?filename=tryjs_myfirst
使用chrome,我访问了w3schools,我意识到<script>标签就是我所需要的.
但是,当我进行离线javascript测试时,我意识到我需要
<script type = 'text/javascript'>
Run Code Online (Sandbox Code Playgroud)
标签.为什么会这样?
我有一个有两件物品的容器.其中一个项是select元素,所以我需要size通过HTML 设置属性.我希望容器中的其他项目伸展其高度以适合容器.我无法弄清楚.我不想明确设置容器的高度,因为我不知道该选择框的大小.
.container {
padding: 5px;
border: 1px solid black;
}
.container .column {
display: inline-block;
width: 40%;
background-color: #AAA;
padding: 5px;
margin: 5px;
vertical-align: top;
height: 100%;
}
select {
width: 100%;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="column">Stretch to fill?</div>
<div class="column">
<select size="15">
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>
<div>Run Code Online (Sandbox Code Playgroud)
我已升级为使用路由器弃用的新Angular 2路由器,并且某些行为已更改.
我遇到问题的页面是搜索页面.我们选择使用HashLocationStrategy.将所有搜索字词放在网址中.路线看起来像这样:
const routes: RouterConfig = [
{ path: '', component: HomeComponent },
{ path: 'search/:term/:cat/:page/:sort/:size/:more', component: HomeComponent },
{ path: 'search/:term/:cat/:page/:sort/:size', component: HomeComponent },
{ path: 'search/:term/:cat/:page/:sort', component: HomeComponent },
{ path: 'search/:term/:cat/:page', component: HomeComponent },
{ path: 'search/:term/:cat', component: HomeComponent },
{ path: 'search/:term', component: HomeComponent },
{ path: 'details/:accountNumber', component: DetailsComponent }
];
Run Code Online (Sandbox Code Playgroud)
我知道查询字符串方法可能更适合所有这些选项,但项目要求由其他人决定......
无论如何,如果我导航到localhost/#/search/Hello使用,this.router.navigate(['/search/Hello']);那么路由器工作正常,一切都很好.在该页面上,如果我尝试this.router.navigate(['/search/World']);然后浏览器地址栏中的URL将相应更新,但组件根本不会更改.
以前我可以routerCanReuse用来表明我确实想重用搜索组件,并routerOnReuse在导航发生时重新运行搜索.我没有看到与这些相同的东西@angular/router.如何使用新的URL参数重新加载当前路由?
我正在运行Angular 2的2.0.0-rc.3版和@ angular/router的3.0.0-alpha.8版.
我正在尝试按照本指南https://angular.io/docs/ts/latest/guide/ngmodule.html引导我的Angular 2 RC5应用程序. 下面是我的代码
import { AppModuleNgFactory } from './app.module.ngfactory';
import {platformBrowser} from "@angular/platform-browser";
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试编译打字稿代码时,我收到以下错误
app\main.ts(1,36):错误TS2307:找不到模块'./app.module.ngfactory'.
如何生成app.module.ngfactory文件?我应该使用哪种工具?
为什么我可以执行以下操作:
var b1, b2;
b1 = b2 = true;
document.write(b1," ", b2);
document.write("<br>");
b1 = !b2;
document.write(b1," ", b2);
document.write("<br>");
b1 = b2 = !true;
document.write(b1," ", b2);Run Code Online (Sandbox Code Playgroud)
然而,当我尝试以下操作时,我收到了一个ReferenceError: invalid assignment left-hand side?
var b1, b2;
b1 = !b2 = true;
document.write(b1," ", b2);Run Code Online (Sandbox Code Playgroud)
很明显,我不能这样做,但我无法找到解释为什么我不能.错误的MDN开发人员指南指出:
某处有意外的任务.例如,这可能是由于赋值运算符和比较运算符的不匹配造成的.虽然单个"="符号为变量赋值,但"=="或"==="运算符会比较一个值.
所有赋值运算符都经过验证,因此为什么不能将它组合成单个运算/链式赋值?
计算图像宽度相对于它在css中包含div的最有效方法是什么?
我有以下代码段设置#image1.width为相对于其父级宽度的百分比.我正在使用百分比,因为我需要在调整屏幕大小时按比例缩放图像.
div {
position: relative;
display: block;
width: 100%;
}
#image1 {
position: absolute;
left: 10%;
top: 10%;
width: 29.43%;
height: auto;
}
#under {
width: 100%;
}Run Code Online (Sandbox Code Playgroud)
<div>
<img id="image1" src="http://placehold.it/206x115">
<img id="under" src="http://placehold.it/700x300/ff00f0/ffffff">
</div>Run Code Online (Sandbox Code Playgroud)
它目前正在按预期工作,除了我必须手动计算每个图像的宽度百分比.即
#image1 dimensions == 206x115
#under dimensions == 700x300
new #image1.width % == #image1.width / #under.width == 206/700 == ~29.43%
Run Code Online (Sandbox Code Playgroud)
我想知道的是,如果有一种calc()方法或类似方法可以实现以简化/简化此过程?
我打算使用,width: calc(100% / 700)但是当屏幕尺寸发生变化时,这显然不起作用.
要重新迭代,#under图像必须与屏幕尺寸和#image保持比例一致.
我希望彼此保留自然图像比率(即,在所有浏览器宽度下,图像的大小是另一个的四分之一).
注:该html …
(我是星球Angular2的新手(从垂死的行星
Flex/Actionscript 移民,所以请原谅这个天真的问题)
在我的项目中运行"ng build"命令后,我发现了一个致命的错误Angular CLi,我最终会在"dist"目录中运行一个正常运行的项目 - 我可以在浏览器中运行,放在一个服务器?
我最终得到了一个充满正确命名的东西的文件夹,等等.我在这里缺少一步吗?
我试图在延迟加载的路由组件中获取父路由参数,但是使用activatedRoute.parent.params似乎不起作用?我有一个实际工作的片段,但它涉及使用'魔术'数组索引号来检索值....
为什么会这样,是否有一个更简洁的方法,我不必检索数组值(this.activatedRoute.pathFromRoot[1])?
我有以下路径,我懒惰加载模块:
parent.route
routes:Routes = [
{
path: "dashboard/:id",
component: dashboard.DashboardComponent,
canActivate: [guard.LoggedInGuard],
children: [
{
path: "my-dock",
loadChildren: 'path/child.module#Child'
}
]
}
];
Run Code Online (Sandbox Code Playgroud)
然后在child.module我的默认组件中有以下内容:
child.component
ngOnInit() {
this.activatedRoute.pathFromRoot[1].params.subscribe((params: Params) => {
console.log(params); // returns {id: "123456789"}
});
this.activatedRoute.parent.params.subscribe((params: Params) => {
console.log(params); // returns {}
});
}
Run Code Online (Sandbox Code Playgroud)
为什么我不能this.activatedRoute.parent.params用来获得id参数?