小编Arū*_*kas的帖子

为什么swagger-ui没有主题?

我非常喜欢大量记录Restful API,特别是"试试看!" 按钮,但swagger-ui界面看起来不是很酷.

而且我无法相信这些神奇的开源工具没有模板(或者我找不到任何模板)?

我不希望它是免费的..像http://getbootstrap.com/有很多网站购买主题(如https://wrapbootstrap.com/),为什么我找不到任何swagger主题的网站?

themes swagger swagger-ui

58
推荐指数
4
解决办法
4万
查看次数

Angular 2.x观察变量变化

我从角度1.x迁移到2.x但是我的大脑仍然在角度1.x中思考,所以对于愚蠢的问题感到遗憾.

我需要的是在我的一个范围变量组件属性发生变化时采取一些操作.我找到了解决方案,但我认为应该有更好的解决方案

export class MyApp {
    router: Router;
    location: Location;
    fixed: boolean = true;

    private set isFixed(value:boolean) {
        this.fixed = value;

        //TODO: look here
        console.log('isFixed changed', value);
    }

    private get isFixed():boolean {
        return this.fixed;
    }

    constructor(router: Router, location: Location) {
        this.router = router;
        this.location = location;
    }
}
Run Code Online (Sandbox Code Playgroud)

看看这条线console.log('isFixed changed', value);它是我需要的,它正在发挥作用.但我通过声明使得它gettersetter,但是是不是有更好的解决方案,以观察变量?像角度1.x一样$scope.$watch

我认为我的组件代码应该是这样的

export class MyApp {
    router: Router;
    location: Location;
    isFixed: boolean = true;

    //TODO: $watch for isFixed change { …
Run Code Online (Sandbox Code Playgroud)

javascript angular

26
推荐指数
2
解决办法
6万
查看次数

Angular2观察路线变化

@RouteConfig([
    {path: '/about', name: 'About', component: About, useAsDefault: true},
    {path: '/test', name: 'Test', component: Test}
])

export class MyApp {
    router: Router;
    location: Location;
    isCollapsed: boolean = true;

    // ON ROUTE CHANGE {
        this.isCollapsed = true;
    // }

    constructor(router: Router, location: Location) {
        this.router = router;
        this.location = location;
    }
}
Run Code Online (Sandbox Code Playgroud)

我需要在每次路线更改时更改变量值,如何在Angular 2.x中观察此事件?

typescript angular

25
推荐指数
3
解决办法
2万
查看次数

Angular 2.x选择DOM元素

我知道它应该很容易但是角度2.0还没有很多例子..

在某些情况下,在我的一个组件中,我需要在body标签上添加class.但是我的应用程序比身体更深,所以我需要类似的东西

angular.element('body').addClass('fixed');
Run Code Online (Sandbox Code Playgroud)

但在Angular 2.0 ..

顺便说一句,我知道我可以以某种方式引导我的应用程序包含body标签,但我认为在其他一些情况下我还是需要选择一些元素,所以我需要一个解决方案如何做这个简单的任务 - "选择元素并添加类到它"

javascript typescript angular

20
推荐指数
3
解决办法
4万
查看次数

Angular 2.x在body标签上绑定类

由于Angular 2.x是在体内引导的,我如何添加[class.fixed]="isFixed"body标签(在my-app之外)?

<html>
<head>
</head>
<body [class.fixed]="isFixed">
  <my-app>Loading...</my-app>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我的app组件看起来像

import {Component} from 'angular2/core';
import {CORE_DIRECTIVES} from 'angular2/common';
import {RouteConfig, ROUTER_DIRECTIVES, Router, Location} from 'angular2/router';
import {About} from './components/about/about';
import {Test} from './components/test/test';

@Component({
    selector: 'my-app',
    providers: [],
    templateUrl: '/views/my-app.html',
    directives: [ROUTER_DIRECTIVES, CORE_DIRECTIVES],
    pipes: []
})

@RouteConfig([
    {path: '/about', name: 'About', component: About, useAsDefault: true},
    {path: '/test', name: 'Test', component: Test}
])

export class MyApp {
    router: Router;
    location: Location;

    constructor(router: Router, location: Location) {
        this.router = …
Run Code Online (Sandbox Code Playgroud)

javascript angular

15
推荐指数
1
解决办法
1万
查看次数

Angular 2 ngFor中不同组件的列表

我知道有很多类似的问题,几乎所有问题都以DynamicComponentLoader答案结束,但我认为下面描述的用例是如此简单和常见(IMO),Angular 2的解决方案应该是直截了当的.

示例用例

我有一系列新闻项目,其属性type描述了它是什么类型的项目.

var items = [
  { id: 1, type: 'text', data: {} },
  { id: 2, type: 'text', data: {} },
  { id: 3, type: 'text-two-columns', data: {} },
  { id: 4, type: 'image-text', data: {} },
  { id: 5, type: 'image', data: {} },
  { id: 6, type: 'twitter', data: {} },
  { id: 7, type: 'text', data: {} }
]
Run Code Online (Sandbox Code Playgroud)

每种不同的类型都有不同的view,完全不同的逻辑.换句话说 - 每个type都有自己的angular2 Component.

所以我试图实现的抽象代码是:

<div *ngFor="let item …
Run Code Online (Sandbox Code Playgroud)

javascript angular

11
推荐指数
3
解决办法
6176
查看次数

Douglas Crockford对Strict Mode示例有错吗?

我敢肯定他不是.我只是不明白他的演讲中的一个例子

http://youtu.be/UTEqr0IlFKY?t=44m

function in_strict_mode() {
    return (function () {
        return !this;
    }());
}
Run Code Online (Sandbox Code Playgroud)

这个不一样吗?

function in_strict_mode() {
    return !this;
}
Run Code Online (Sandbox Code Playgroud)

如果is_strict_mode()我愿意method那么我同意,因为this那样会指向包含对象的方法,例如

my_object.in_strict_mode = function() {
    return (function () {
        return !this;
    }());
}
Run Code Online (Sandbox Code Playgroud)

但是为什么他在他的例子中做到了(这是一个简单的函数,而不是一个对象的方法)?

javascript strict

7
推荐指数
2
解决办法
246
查看次数

Angular 2.x改变头部的<title>(在我的app之外)

我认为应该很容易,但我找不到.

我有类似的东西

<html>
<head>
  <title>{{'a' + 'b'}}</title>
</head>
<body>
  <my-app>Loading...</my-app>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

好像我无法访问外面的任何东西my-app.

在角度1.x中它很容易,我能够添加ng-app任何元素(<html ng-app="myApp">).

现在我想我只能在体内引导.

我知道我可以手动引导某种方式(没有尝试),但动态更改单页应用程序中的标题应该是超级简单的,不应该吗?

javascript angularjs

7
推荐指数
1
解决办法
3229
查看次数

"escapeshellarg"足够安全吗?

场景:

  1. 用户输入视频网址

  2. php下载视频 exec( "youtube-dl " . escapeshellarg($url) );

题:

它足够安全吗?

谢谢!

php security exec youtube-dl

5
推荐指数
1
解决办法
5417
查看次数

JSON API用于非资源响应

目前,我正在研究新产品,并为公共和内部需求制作REST API。我从{json:api}规范开始,对它感到非常满意,直到遇到一些无法找到答案的问题。

根据JSON API规范,每个资源都必须包含id

http://jsonapi.org/format/

每个资源对象必须包含一个id成员和一个type成员。id和type成员的值必须是字符串。

在很多情况下都可以,但不是全部。

我们的大多数端点都是关于“资源”的

如果我要收集“东西”(http://example.com/things

{
  "data": [{
    "type": "things",
    "id": "1",
    "attributes": {
      "title": "first"
    },
    "links": {
      "self": "http://example.com/things/1"
    }
  }, {
    "type": "things",
    "id": "1",
    "attributes": {
      "title": "second"
    },
    "links": {
      "self": "http://example.com/things/2"
    }
  }]
}
Run Code Online (Sandbox Code Playgroud)

如果我只要求一个“物”资源(http://example.com/things/1

{
  "data": {
    "type": "things",
    "id": "1",
    "attributes": {
      "title": "first"
    },
    "links": {
      "self": "http://example.com/things/1"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但是如何处理与资源无关且没有ID的终结点呢?

例如,在我们的应用程序中,存在一个端点http://example.com/stats,该端点应返回当前登录用户user的统计信息。喜欢 …

api rest json-api jsonapi-resources

5
推荐指数
1
解决办法
962
查看次数

如何在 MongoDb 中存储对其他集合的引用

我需要存储对其他集合的引用,但我无法决定是将它存储为字符串还是ObjectId(). 我认为可以通过两种方式进行(在 mongo shell 中):

作为 ObjectId

db.books.findOne({_id:ObjectId("54bc1287c582714e9f062591")});
{
    "_id" : ObjectId("54bc1287c582714e9f062591"),
    "title" : "Book title",
    "author_id" : ObjectId("54bc12da5f5e8854718b4568")
}
Run Code Online (Sandbox Code Playgroud)

作为字符串

db.books.findOne({_id:ObjectId("54bc1287c582714e9f062591")});
{
    "_id" : ObjectId("54bc1287c582714e9f062591"),
    "title" : "Book title",
    "author_id" : "54bc12da5f5e8854718b4568"
}
Run Code Online (Sandbox Code Playgroud)

我不会搜索 by author_id,所以我不需要任何索引。我会带一本书,然后会带一位作者author_id。顺便说一句,这只是一个例子books

mongodb

3
推荐指数
1
解决办法
1501
查看次数

Angular2指令与范围

Angular2中的指令没有"范围",而组件则没有.但就我而言,我需要Directive来创建一个范围.查看我的App组件 - 它有一个HTML模板,并且该foo指令可以出现的任何元素上都有ANYWHERE .这应该从服务中获取一些日期并将其分配给元素.

在Angular1中,它很容易......指令可以有自己的范围.但在Angular 2中,我找不到任何(甚至是肮脏的)方法来实现这一点.

它看起来像一个简单的任务,不是吗?

@Directive({
  selector: '[foo]'
})
class FooDirective {
  @Input()
  public id:string;

  public bar;

  constructor() {
     this.bar = 'This is the "bar" I actually need. It is taken from DB let's say..' + this.id;
  }
}




@Component({
  selector: 'app',
  template: `
     <div foo id="2">
       This is random content 1: {{bar}}
     </div>

     <div foo id="2">
       This is random content 2: {{bar}}
     </div>
  `,
  directives: [FooDirective]
})
class App {
  bar:string = 'This should be …
Run Code Online (Sandbox Code Playgroud)

javascript angular2-directives angular

3
推荐指数
1
解决办法
2612
查看次数

AngularJs - 从指令获取默认HTML

我正在构建angularJs指令,我需要在用模板替换之前获取元素html.例如:

<edit>Default title</edit>
Run Code Online (Sandbox Code Playgroud)

我的指令如下:

.directive('edit', function() {
    return {
        restrict: "EA",
        scope: {},
        template: '<h1 ng-show="!edit_mode">{{variable.value}}</h1><input ng-show="edit_mode" ng-model="variable.value" />',
        link: function( scope, element ) {
            scope.edit_mode = false;
            scope.variable = {
                value: element.html() 
            }
            console.log( scope.variable );
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

但在控制台中我看到(当然在网页中相同)

Object {value: "<h1 ng-show="!edit_mode" class="ng-binding">{{variable.value}}</h1><input ng-show="edit_mode" ng-model="variable.value" class="ng-pristine ng-valid">"}
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-directive

1
推荐指数
1
解决办法
197
查看次数