我在web.config文件中指定了会话超时.当会话超时时,我没有重定向到登录页面,但是我收到错误,说对象引用没有设置为实例.
谁能告诉我这方面的解决方案?
我知道有很多关于CORS的问题,但它们似乎没有回答我的问题.
所以我有一个用Angular编写的客户端应用程序,用于创建移动应用程序(使用Apache Cordova).将从移动设备加载html文件和JavaScript文件.当我模拟这个并且我向REST API服务器发送请求时,我首先得到"No'Access-Control-Allow-Origin'标头出现在所请求的资源上.http://localhost:82因此不允许来源".所以我添加了标题("Access-Control-Allow-Origin:*"); 在我的PHP REST API服务器中.我无法指定特定域,因为请求将来自移动设备.
现在,当凭证标志为真时,我不能在'Access-Control-Allow-Origin'标题中使用"通配符'*'."
我终于找到了一个解决方案,但我不确定这样做是否安全.
在我的PHP REST API服务器中,我添加了这个:
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: " . $_SERVER['HTTP_ORIGIN']);
header("Access-Control-Allow-Headers: *, X-Requested-With, Content-Type");
header("Access-Control-Allow-Methods: GET, POST, DELETE, PUT");
}
Run Code Online (Sandbox Code Playgroud)
请告知这种工作方式.如果它不安全或根本没有好处,请告诉我如何解决这个问题?
非常感谢!
这是一个AngularJS等效的Angular ng-container?
或者我应该用transclude指令自己创建一些东西?
用例示例:
具有隔行对,三元组等的表格:
<table><tr>
<ng-container ng-repeat="item in items">
<td>{{ item.a }}</td>
<td>{{ item.b }}</td>
</ng-container>
</tr></table>
Run Code Online (Sandbox Code Playgroud)
DOM树中不应该有额外的级别,而是<td>s应该是<tr>元素的直接子级.
HTML列表存在类似的问题,尤其是定义列表,其中<dt>/ <dd>元素应该是直接子元素,<dl>而它们通常成对存在.
表格式的数据排列display:grid:
<div style="display: grid; grid-template-columns: auto auto">
<ng-container ng-repeat="item in items">
<div>{{ item.a }}</div>
<div>{{ item.b }}</div>
</ng-container>
</div>
Run Code Online (Sandbox Code Playgroud)
这种情况甚至更成问题,因为DOM树中存在的容器元素导致整个布局中断,因为它被渲染为单元而不是其子元素.
我有一个Angular 4项目,使用angular-cli 1.0.x创建.此时,angular-cli在我的项目中升级到1.1.1.
我有一个资产文件夹,当我在其中放入一个css文件时,可以使用它.但是当我将css文件重命名为scss时,它不是由angular-cli编译的.
要将scss文件编译为css,我需要做什么?
这是我的项目的package.json:
{
"name": "my project",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "4.1.3",
"@angular/common": "4.1.3",
"@angular/compiler": "4.1.3",
"@angular/core": "4.1.3",
"@angular/forms": "4.1.3",
"@angular/http": "4.1.3",
"@angular/platform-browser": "4.1.3",
"@angular/platform-browser-dynamic": "4.1.3",
"@angular/router": "4.1.3",
"@angular/upgrade": "4.1.3",
"@axinpm/ang-core": "^0.2.3",
"chart.js": "2.5.0",
"core-js": "2.4.1",
"moment": "2.18.1",
"ng2-charts": "1.5.0",
"ng2draggable": "^1.3.2",
"ngx-bootstrap": "1.6.6",
"rxjs": "5.4.0",
"ts-helpers": "1.1.2",
"zone.js": "0.8.11"
},
"devDependencies": {
"@angular/cli": "1.1.1",
"@angular/compiler-cli": …Run Code Online (Sandbox Code Playgroud) 我想为可以获取参数的类创建一个装饰器函数.
例
@Plugin("My first Plugin")
class myFirstPlugin {
...
}
Run Code Online (Sandbox Code Playgroud)
我试过这个,但它不起作用:
function Plugin(constructor: Function, name:string){
console.log("Plugin found: " + name);
}
Run Code Online (Sandbox Code Playgroud)
我在WebStorm中遇到错误说:
TS2346:提供的参数与呼叫目标的任何签名都不匹配
我该如何编写这个装饰器功能?
我有一个自定义消息系统,我试图转换,所以它可以支持插件.
该系统有生产者和消费者.两者都必须指定它们生成或使用的消息类型.
对于消费者来说,要实现的接口是
IConsumer<AMessage>
Run Code Online (Sandbox Code Playgroud)
我有一个插件dll中的消费者,它实现了这个接口:
FileProcessor : IConsumer<FileMessage>
Run Code Online (Sandbox Code Playgroud)
同
FileMessage : AMessage
Run Code Online (Sandbox Code Playgroud)
而AMessage是一个抽象类.IConsumer和AMessage都在主(Core)程序集中.
现在,在核心中,它加载了插件并扫描并找到了我希望将消费者链接到消息系统的消费者.
为了简化这里的事情,我只是尝试将消费者放在一个变量中:
IConsumer<AMessage> consumer = IConsumer<AMessage> new FileProcessor();
Run Code Online (Sandbox Code Playgroud)
我在VS中收到警告:
可疑演员:解决方案中没有类型继承自'TestPlugin.FileProcessor'和'Core.IConsumer'.
当我执行时,我得到了
System.InvalidCastException:无法将类型为'TestPlugin.FileProcessor'的对象强制转换为'Core.IConsumer`1 [Core.AMessage]'.
为什么这个演员会失败?我怎么解决这个问题?
--edit1--
根据评论,这里是IProducer和IConsumer的完整定义:
public interface IProducer<out T> : IProcessor where T : AMessage
{
event MessageSender<T> SendMessage;
}
public interface IConsumer<in T> : IProcessor where T : AMessage
{
ProcessResult ProcessBean(T bean);
}
Run Code Online (Sandbox Code Playgroud)
当生产者在系统中链接时,他们定义T,之后只有具有相同类型T的消费者可以链接到该生产者.例如:
var channel = flow.From(FileProducer).To(FileConsumer);
Run Code Online (Sandbox Code Playgroud)
随着flow.From:
public Channel<T> From<T>(IProducer<T> producer) where T : AMessage
{
...
}
Run Code Online (Sandbox Code Playgroud)
和频道.要:
public class Channel<T> …Run Code Online (Sandbox Code Playgroud) 我希望能够有一个包含两个项目的单选按钮组,以便进行"是 - 否"切换.
以下代码段有效,但作为item.value 具有"true"/"false" 字符串值
<input type="radio" [formControl]="item" name="{{item.id}}" value=true>
<input type="radio" [formControl]="item" name="{{item.id}}" value=false>
Run Code Online (Sandbox Code Playgroud)
如何在item.value中获取布尔值?
我尝试了以下但没有成功:
<input type="radio" [formControl]="item" name="{{item.id}}" [ngValue]=true>
<input type="radio" [formControl]="item" name="{{item.id}}" [ngValue]=false>
Run Code Online (Sandbox Code Playgroud)
它抛出
Can't bind to 'ngValue' since it isn't a known native property
Run Code Online (Sandbox Code Playgroud)
我正在使用Angular 2 RC4和Angular Forms 0.2.0.
一般问题
我想要设计可重用的 Angular 组件的样式以匹配特定客户端项目的样式。
我在一个单独的项目中维护可重用组件,并从中生成一个 npm 包。该包被发布到私有 NPM 存储库 (Sinopia),然后安装到多个客户端项目中。
当然,一般样式是特定于组件的,但是颜色和字体(例如)应该与客户端项目相匹配。
如何最好地将客户端项目中定义的颜色和字体等样式应用到可重用组件?
当前实施情况
目前我正在使用https://github.com/jvandemo/generator-angular2-library来搭建可重用组件库。它生成一些 Gulp 任务,让我构建一个 dist 版本。发布该 dist 并使用已发布的包效果很好,但构建的代码使我很难找出可行的主题策略。
Gulp 构建任务将在最终代码中内联 HTML 和 CSS 资源。
示例组件
@Component({
selector: 'app-messages',
templateUrl: './messages.component.html',
styleUrls: ['./messages.component.scss'],
})
export class MessagesComponent {
constructor(private messagesService: MessagesService) {
}
}
Run Code Online (Sandbox Code Playgroud)
在构建过程中被“扁平化”
var MessagesComponent = (function () {
/**
* @param {?} messagesService
*/
function MessagesComponent(messagesService) {
this.messagesService = messagesService;
}
...
return MessagesComponent;
}());
MessagesComponent.decorators = [
{ type: Component, args: [{
selector: …Run Code Online (Sandbox Code Playgroud) 我想使用 TypeScript Decorator 创建一个属性 getter 和 setter,但我一直坚持定义在属性更改或请求时运行的函数。
如果我的装饰器有以下用法Field.watch:
export class Test {
...
@Field.watch({onSet: this.resetCssCache})
public layoutId = 0;
...
public resetCssCache() {
...
}
...
}
Run Code Online (Sandbox Code Playgroud)
装饰器的实现是:
export class Field {
public static watch(watchers: { onGet?: () => any, onSet?: (newValue: any, oldValue: any) => any }): Function {
return (target: any, key: string) => {
// property getter
const getter = function() {
return this['_' + key];
};
// property setter
const setter = function(newVal) { …Run Code Online (Sandbox Code Playgroud) 在 OpenAPI 3 中,是否可以在全局级别定义 SecurityScheme,然后在某些端点覆盖它以不使用安全性(对于公共可访问端点)?
例如(取自https://swagger.io/docs/specification/authentication/bearer-authentication/)
openapi: 3.0.0
...
# 1) Define the security scheme type (HTTP bearer)
components:
securitySchemes:
bearerAuth: # arbitrary name for the security scheme
type: http
scheme: bearer
bearerFormat: JWT # optional, arbitrary value for documentation purposes
# 2) Apply the security globally to all operations
security:
- bearerAuth: [] # use the same name as above
Run Code Online (Sandbox Code Playgroud)
然后使给定端点可公开访问(不受保护)
paths:
/unprotected/path:
get:
security: []
Run Code Online (Sandbox Code Playgroud)
或者应该以另一种方式完成?
更新这个问题被标记为重复,但另一个问题处理有关 Swagger 2.x 的问题,并且由于语法不同,我认为这个问题和答案应该保留。