我很惊讶没有确切的答案:
Root/forChild的方法是什么?
例如在RouterModule中:
Router.forRoot(routes)
Run Code Online (Sandbox Code Playgroud) 我在 VSCode( 1.44.0-insider ) 中使用 Angular9 创建 Angular Elements 时收到一个奇怪的警告:
export class AppModule {
constructor(private injector: Injector) {
const helloElement = createCustomElement(HelloComponent, {injector});
customElements.define('my-hello', helloElement);
}
ngDoBootstrap() {}
}
Run Code Online (Sandbox Code Playgroud)
类型helloElement
不接受,并带有来自打字稿的错误消息:
“NgElementConstructor”类型的参数不可分配给“CustomElementConstructor”类型的参数
我有指令做这样的事情:
app.directive('custom', function(){
return {
restrict:'A',
link: function(scope, element){
element.bind('click', function(){
alert('want to prevent this');
});
}
}
});
Run Code Online (Sandbox Code Playgroud)
是的,有必要为这种情况做jQuery-way绑定.
现在,如果满足某些条件,我想停止此事件(单击)传播.
试图做:
$event.stopPropagation();
$event.preventDefault();
Run Code Online (Sandbox Code Playgroud)
但它没有帮助.
这里小提琴 - 例如http://jsfiddle.net/STEVER/5bfkbh7u/
我正在使用ui-router 1.0.0-alpha.5.旧事件在那里被弃用.
所以我想转换
$rootScope.$on('$stateChangeStart', ($event) => {
//some logic
$event.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
成:
$transitions.onEnter({}, ($transition$) => {
//...
});
Run Code Online (Sandbox Code Playgroud)
我怎么能防止这里的默认动作?
我正在尝试组合Angular1.5 + Typescript.已安装所需类型:
npm install @types/angularjs
但仍然看到错误:
错误TS2307:找不到模块'angular'
已尝试过不同的选择:
import 'angular';
import 'angularjs'; //that is name inside @types
import angular from 'angularjs';
import * as angular from 'angular';
Run Code Online (Sandbox Code Playgroud)
我正在使用:
"ts-loader": "1.0.0",
"typescript": "2.0.7",
"webpack": "1.13.3",
"webpack-dev-server": "1.16.2"
Run Code Online (Sandbox Code Playgroud)
tsconfig非常标准:
{
"compilerOptions": {
"target": "es5",
"noImplicitAny": false,
"sourceMap": false,
"lib": ["es6", "dom"],
"typeRoots": ["./node_modules/@types"]
},
"exclude": ["node_modules"]
}
Run Code Online (Sandbox Code Playgroud)
已经简化了webpack配置:var webpack = new require('webpack');
module.exports = {
context: __dirname + '/src',
entry: './index.ts',
output: {
path: './dist',
filename: 'app.bundle.js'
}, …
Run Code Online (Sandbox Code Playgroud) 我决定对angular-cli使用扩展的webpack配置,所以我运行命令ng eject
.
看起来除了环境文件替换之外,一切都正常工作,在angular-cli.json中指定:
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
Run Code Online (Sandbox Code Playgroud)
现在根本没有替换,它总是使用"environments/environment.ts"文件.
有没有办法让它在没有重大更改webpack配置的情况下工作?
还为angular-cli github项目创建了一个问题.
我正在使用TransferState进行SSR,并想知道当我们这样做时谁保证
http.get(...).subscribe(data => {
transferState.set(DATA_KEY, data)
})
Run Code Online (Sandbox Code Playgroud)
数据将存储在transferState中?因为http.get是异步操作,并且可以生成内容并将其提供给没有此数据的客户端.
更新的堆栈跟踪中的任何更改始终会导致返回globalZoneAwareCallback
。您如何找出引发变化的原因?
在调试方面,最好有一个清晰的画面。
我们的想法是从所有html文件中获取1个JS文件.之后通过require使用它:
templateUrl: require('./views/user-list.html')
Run Code Online (Sandbox Code Playgroud)
你能和我分享经验吗?我正在谷歌搜索它,发现几个装载webpack但不知道该使用什么.
Ahead-of-Time Compilation(或AoT)是Angular2中提供的一项功能.但我在官方网站上找不到有关它的好解释.
有人可以明确定义它吗?
angular ×5
angularjs ×4
javascript ×2
webpack ×2
angular-cli ×1
angular2-aot ×1
debugging ×1
templates ×1
typescript ×1