将角度2升级到RC5后,我收到如下警告,要求我将组件移动到模块声明:
NgModule AppModule通过"entryComponents"使用AcademylistComponent但它既未声明也未导入!最终结束后,此警告将成为错误.
我在路由器配置文件中引用了这些组件.看起来像这样:
import {provideRouter,RouterConfig} from '@angular/router';
import {AcademylistComponent} from '../modules/home/component/academyList.component';
import {CourselistComponent} from '../modules/home/component/courseList.component';
import {CreateacademyComponent} from '../modules/home/component/createAcademy.component';
import {ReportsComponent} from '../modules/home/component/reports.component';
import {AuthenticatedGuard} from '../guards/authenticated.guard';
export const routes: RouterConfig = [
{
path: '',
redirectTo:'/home',
terminal:true},
{
path: 'home',
canActivate: [AuthenticatedGuard],
children: [
{path: '', component: AcademylistComponent},
{path: 'my-academies', component: AcademylistComponent},
{path: 'my-courses', component: CourselistComponent},
{path: 'create-academy', component: CreateacademyComponent},
{path: 'reports', component: ReportsComponent}
]
}
];
export const APP_ROUTER_PROVIDERS = [
provideRouter(routes)
];
Run Code Online (Sandbox Code Playgroud)
当我将组件移动到ng模块的declarations阵列并将其导入那里时,路由配置文件确实开始给我Cannot …
我有一个问题,即EventEmitter不会将值输出到父组件.这是我如何设置.
main.component.ts(简短版)
...
@Component({
selector: 'my-app',
templateUrl: '/app/views/main.ejs',
directives: [ROUTER_DIRECTIVES],
providers:[AuthService],
inputs:['userLoggedIn']
})
@RouteConfig([
{path:'/logout', name: 'Logout', component: AuthComponent},
])
export class AppComponent implements OnInit, CanReuse{
constructor(private _auth_service: AuthService){
this._auth_service.authChanged.subscribe(data=>this.authChangedHandler(data));
}
public authChangedHandler($event){
alert($event);
}
}
...
Run Code Online (Sandbox Code Playgroud)
auth.component.ts(简短版)
export class AuthComponent implements OnInit, CanReuse{
public loggedIn = false;
public user = {};
@Output()
authChanged: EventEmitter<string>;
public selectedTab = "/login";
constructor(private _router: Router, private _location:Location,private _http: Http, private _auth_service: AuthService){
this.authChanged = new EventEmitter();
this.authChanged.emit("authChanged");
}
}
Run Code Online (Sandbox Code Playgroud)
main.ejs(短版)
<nav (authChanged)="authChangedHandler($event)"></nav>
<router-outlet></router-outlet> …Run Code Online (Sandbox Code Playgroud) 我正在尝试将Angular 2集成到Sails Js应用程序中.我是两个人的新手.我一直在这里关注这个官方教程.它在独立模式下使用静态http服务器工作正常但是当我尝试集成到sails应用程序时,我遇到以下问题:
1 - 如何在本地node_modules文件夹中引用angular2 js.每次我这样做,sails都会将它解释为一条路线,并为我的脚本提供404.例如:
<script src="node_modules/angular2/dist/angular2.min.js"></script>
我现在能够使用cdnjs链接克服上述问题,但我想知道更好/更合适的解决方案.
2 - 我将tsc和tsc -w脚本添加到我的package.json中,但即使sails lift --verbose我没有得到任何输出或错误.以下是我将脚本添加到json文件的方法:
"scripts": {
"tsc": "tsc",
"tsc:w": "tsc -w",
"debug": "node debug app.js",
"start": "node app.js"
}
Run Code Online (Sandbox Code Playgroud)
最后我必须使用-g安装typescript并手动编译.这有效,但同样,它预计将与脚本一起使用.知道自己错过了什么会很棒.
3 - 跳过箍以摆脱上述错误后,当我再次抬起服务器时,它给了我更多的404错误,似乎来自system.src.js我并且我无法弄明白.请参阅下面的控制台screengrab.
我想我可能在设置sails中的角度应用程序目录时犯了一个错误.为了确保我们涵盖所有内容,这里是我正在使用的目录结构.帆应用程序还没有任何内容.这就是为什么以下路径仅适用于角度相关的工件和资产.
在assets文件夹中:
应用
│├──app.component.ts
│└──main.ts
当然.ts文件被编译为js.
在sails views文件夹中,我有layout.ejs,其中包含以下内容:
.
.
.
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.34.2/es6-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.17/system-polyfills.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.1/angular2-polyfills.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.17/system.src.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.0.7/rx.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.1/angular2.dev.js"></script>
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js' …Run Code Online (Sandbox Code Playgroud) 我们有一个 AWS EC2 负载均衡器,并且上面安装了 SSL 证书。但是池中的服务器仍然在端口 80 和非 SSL 协议上运行。
问题是我无权访问负载平衡器,但我仍然必须路由非 SSL 流量以保护 HTTPS。我尝试在 中添加以下内容,htaccess但它不起作用并且可以理解,这是因为服务器仍在 HTTP 上运行。
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Run Code Online (Sandbox Code Playgroud)
我在 PHP 代码中尝试了同样的事情,但也没有用。
if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") {
$url = "https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
redirect($url);
exit;
}
Run Code Online (Sandbox Code Playgroud)
所以,我知道服务器仍在 HTTP 上运行,并且证书仅应用于负载平衡器。在这种情况下强制进行此类重定向的最佳解决方案是什么。我能想到的一种解决方案是解析代码中的 URL 以查看它是否http://存在并重定向。这可能有效,但我真的不认为它是一个干净的最终解决方案。AWS EC2 有没有办法以这种方式重定向?我不熟悉 AWS EC2。
另外,是否有任何服务器参数可能表明服务器正在端口 80 上运行,但 HTTPS 仍然是on?
我正在尝试实现异步自定义验证,我有如下的验证类
export class CustomValidators{
_auth_service;
constructor(auth_service:AuthService){
this._auth_service = auth_service;
}
usernameTaken(control: Control) {
console.log(this._auth_service);
let q = new Promise<ValidationResult>((resolve, reject) => {
this._auth_service.emailtaken('email='+control.value).subscribe(data=>{
var result = data.json().result;
console.log(result);
if(result===true){
resolve({"usernameTaken": data});
}else{
resolve(null);
}
});
});
return q;
}
}
Run Code Online (Sandbox Code Playgroud)
在我的组件中
this.customValidators = new CustomValidators(this._auth_service);
Run Code Online (Sandbox Code Playgroud)
我将它添加到表单控件中
this.emailControl = new Control('',Validators.compose([Validators.required, Validators.pattern(ConfigService.EMAIL_REGEX)]),this.customValidators.usernameTaken);
Run Code Online (Sandbox Code Playgroud)
您可以看到我正在尝试在验证器中注入服务.然后要在我的组件中使用验证器函数,我必须创建验证器的对象并使用它的方法.我已经调试,看到该this._auth_service属性出现undefined在我的验证方法中.它似乎在我的验证器构造函数中填充得很好.
我不想使用验证器作为指令,我理解使注入服务变得容易.
可能是什么问题呢?
我正在为我的客户在这个网站上工作.
问题是主页上的下拉菜单隐藏在嵌入式youtube播放器后面.这似乎是一个涉及z-index的简单css问题,但我无法解决它.也许它与youtube嵌入有关.
我试图设置菜单的z-index但它似乎没有效果.
我几乎忘了告诉你IE9上的问题具体发生了.
另外,我不是css专家,所以请指出问题所在.
angular ×4
typescript ×3
.htaccess ×1
amazon-ec2 ×1
angularjs ×1
css ×1
html ×1
javascript ×1
node.js ×1
php ×1
sails.js ×1
ssl ×1
z-index ×1