所以我正在开发一个Angular2应用程序,只是通过引导Angular2,我发送了超过250个请求,几乎每个@angular/core节点模块包中的js文件:
具体来说,一切似乎都是从中导入的zone.js:101.这是我的应用程序入口点,只是为了证明我没有做任何不寻常的事情:
import { bootstrap } from '@angular/platform-browser-dynamic';
import { LiveComponent } from './components/live.component';
bootstrap(LiveComponent);
Run Code Online (Sandbox Code Playgroud)
这是我的HTML:
<!-- 1. Load libraries -->
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="js/systemjs.config.js"></script>
<script>
System.config({
defaultJSExtensions: true
});
System.import('js/angular2/main').catch(function(err){ console.error(err); });
</script>
Run Code Online (Sandbox Code Playgroud)
这是systemjs.config.js:
(function(global) {
// map tells the System loader where to look for things
var map = {
'app': 'app', // 'dist',
'rxjs': …Run Code Online (Sandbox Code Playgroud) 假设我有以下Angular 2组件,其中foo是一个未绑定到表单的对象,而不是来自Input():
@Component({
selector: 'foo',
templateUrl: '/angular/views/foo.template.html',
directives: [ContentEditableDirective, ROUTER_DIRECTIVES],
providers: [FooService]
})
export class FooComponent implements OnInit {
public foo: Foo = new Foo();
constructor(
private fooService: FooService,
private route : ActivatedRoute,
private router : Router) {}
ngOnInit() {
let id = +this.route.snapshot.params['id'];
this.fooService.getFoo(id).subscribe(
foo => {
this.foo = foo;
// I have this.foo, we should watch for changes here.
Observable. // ???
.debounceTime(1000)
.subscribe(input => fooService.autoSave(this.foo));
},
error => console.log(error)
);
}
}
Run Code Online (Sandbox Code Playgroud)
如何订阅 …
我有一组Angular路由,带有实体列表,有两条子路由,用于创建这样的实体和编辑现有实体.实体列表resolver附加了它以在显示组件之前预取组件的数据.这些路由可以总结如下,进一步了解如何在代码中描述这些路由.
/items/items/create/items/:itemId/edit但是,如果我在/items/create,并成功创建一个项目,导航"返回" /items或任何编辑路线,甚至返回到/将不会导致我的解析器获取像我期望的更新数据.尽管将runGuardsAndResolvers属性设置为"始终".我的理解是这个属性应该能够实现我正在寻找的功能.
为什么会这样,我怎样才能启用我正在寻找的功能,而不需要在我的组件中订阅路由器事件和复制逻辑.
const itemRoutes: Routes = [
{
path: '', // nb: this is a lazily loaded module that is itself a child of a parent, the _actual_ path for this is `/items`.
runGuardsAndResolvers: 'always',
component: ItemsComponent,
data: {
breadcrumb: 'Items'
},
resolve: {
items: ItemsResolver
},
children: [
{
path: 'create',
component: CreateItemComponent,
data: { …Run Code Online (Sandbox Code Playgroud) 所以我试图根据是否选中子复选框,使用Knockout.js为元素添加一个类.为此,我试图将this参数传递给我的函数.目前,我的删节DOM结构如下:
<tr data-bind="css: { selected: isRowChecked(this) }">
<td><label><input type="checkbox"></label></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我的isRowChecked功能是这个(我使用jQuery来定位输入):
function isRowChecked(elem) {
var checkbox = $(elem).find('input[type="checkbox"]');
return checkbox.checked;
}
Run Code Online (Sandbox Code Playgroud)
然而,如果我console.log elem得到的是全局窗口对象.
使用jQuery完全解决这个问题是不可行的,因为我工作的项目几乎已经完全使用了淘汰赛.有任何想法吗?
我正在尝试为搜索功能创建自己的自定义外观,但我遇到了一些困难:
type: Symfony\Component\Debug\Exception\FatalErrorException
message: Call to undefined method Illuminate\Foundation\Application::create()
file: H:\myproj\vendor\laravel\framework\src\Illuminate\Container\Container.php
line: 165
Run Code Online (Sandbox Code Playgroud)
此错误是由我的代码命中引起的:
Search::indexObject();
Run Code Online (Sandbox Code Playgroud)
我的Search门面设置如下:
<?php
namespace MyProj\Search;
use Illuminate\Support\ServiceProvider;
class SearchServiceProvider extends ServiceProvider {
public function register() {
$this->app->bind('search', 'MyProj\Search\Search');
}
}
Run Code Online (Sandbox Code Playgroud)
<?php
namespace MyProj\Facades;
use Illuminate\Support\Facades\Facade;
class Search extends Facade {
public static function getFacadeAccessor() {
return 'search';
}
}
Run Code Online (Sandbox Code Playgroud)
<?php
namespace MyProj\Search;
use Elasticsearch\Client;
use Credential;
class Search {
private $elasticSearchClient;
public function __construct() {
$this->elasticSearchClient = new Client(array(
'hosts' => …Run Code Online (Sandbox Code Playgroud) 如何[routerLink]从 Angular Router v3扩展指令,以便我可以自己包装一些自定义功能?我查看了RouterLinkWithHref指令,看来这就是我想要扩展的内容,所以我制作了这个:
import {Directive, Input} from '@angular/core';
import {RouterLinkWithHref} from "@angular/router";
import {Model} from "../Classes/Model.class";
@Directive({
selector: 'a[extendedRouterLink]'
})
export class ExtendedRouterLinkDirective extends RouterLinkWithHref {
@Input('extendedRouterLink') model : Model;
// Future custom logic
}
Run Code Online (Sandbox Code Playgroud)
我尝试像这样使用它:
<a [extendedRouterLink]="model">
Run Code Online (Sandbox Code Playgroud)
我将它包含在directives我的组件数组中:
...
directives: [ROUTER_DIRECTIVES, ExtendedRouterLinkDirective],
...
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下运行时错误:
“模板解析错误:无法绑定到‘extendedRouterLink’,因为它不是已知的本机属性”
如果我extends RouterLinkWithHref从我的指令中删除,它可以正常工作而不会出错。我究竟做错了什么?
typescript angular2-directives angular2-routing angular2-router3 angular
好的,我刚开始看看MySQLi准备好的语句.这对我来说是一个很大的进步,因为我对MySQL和PHP都是非常新的,所以我对这个概念(可能大约一个小时的价值)有一个非常脆弱的把握,所以你的答案必须用同样的措辞,抱歉这个.
我想知道的是,如果我正确地写了一份准备好的陈述.没有什么比学习一个不正确并习惯它的方法更糟糕的了,因此编写整个项目效率低下.
要点:我有一个注册用户的函数,然后返回插入的id,因此是用户的引用id.
以前,我只是查询数据库,尽管使用了mysql_real_escape_string()类似的安全措施,但我被告知存在安全风险.
现在,它看起来像这样:(假设为了这个问题,定义了所有引用的变量,绑定的参数是字符串,并且所有被调用的函数都存在且正在工作).
function registerUser($username, $fname, $email, $password, $region, $activation) {
$uniqueSalt = uniqueSalt();
$password = sha1($uniqueSalt . $password);
$mysqli = mysqli_connect('localhost', 'root', '', 'database');
if ($stmt = $mysqli->prepare("INSERT INTO `users` VALUES('', ?, ?, ?, ?, '$password', '$uniqueSalt', '$activation')") ) {
$stmt->bind_param("ssss", $username, $fname, $email, $region);
$stmt->execute();
$stmt->close();
} else {
echo 'error preparing statement';
}
return mysqli_insert_id($mysqli);
}
Run Code Online (Sandbox Code Playgroud)
它似乎有效,但是:
1)这是执行预准备语句的正确语法吗?
2)我已将此函数所在的文件(称为function.php)包含在另一个名为init.php的文件中,该文件先前已定义该变量$mysqli.我发现如果我没有包含
$mysqli = mysqli_connect('localhost', 'root', '', 'database');
Run Code Online (Sandbox Code Playgroud)
我会收到一个错误.为什么我必须在函数内重新定义它?
3)当我之前在使用准备return mysql_insert_id() …
我有一个在InnoDB引擎上运行的MySQL表squares,它有大约2,250,000行,具有以下表结构:
`squares` (
`square_id` int(7) unsigned NOT NULL,
`ref_coord_lat` double(8,6) NOT NULL,
`ref_coord_long` double(9,6) NOT NULL,
PRIMARY KEY (`square_id`),
KEY `ref_coord_lat` (`ref_coord_lat`),
KEY `ref_coord_long` (`ref_coord_long`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Run Code Online (Sandbox Code Playgroud)
第一列square_id保持一个简单的递增值,从0到2.25M,而ref_coord_lat&分别ref_coord_long保持一组点的十进制度的纬度和经度坐标.
这是一个只读表.不会添加其他行,并且需要针对它运行的唯一查询如下:
SELECT * FROM `squares` WHERE
`ref_coord_lat` BETWEEN :southLat AND :northLat AND
`ref_coord_long` BETWEEN :westLong AND :eastLong
Run Code Online (Sandbox Code Playgroud)
...冒号后面的值是PHP PDO占位符.本质上,此查询的目标是获取表格中当前位于Google地图窗口视口中的所有坐标点,该窗口由查询中的4个坐标限定.
我已经限制了使用Google Maps API运行此查询的缩放级别,因此可以获取的最大行数为~5600.随着缩放级别的增加,合成的提取总量显着减少.
直接在PHPMyAdmin中运行这样的示例查询需要1.40-1.45秒.这太长了.我已经在运行标准索引,ref_coord_lat并且ref_coord_long查询时间从大约5秒开始下降,但对于最终用户期望及时响应的地图来说,这仍然太大了.
我的问题很简单:如何进一步优化此表/查询以提高获取结果的速度?
我正在使用PHP-FFMpeg存储库在我的Laravel应用程序中进行一些视频工作,但我遇到了一些设置它的问题.一旦我安装了PHP-FFMpeg repo,我就尝试创建一个FFMpeg实例:
$ffmpeg = \FFMpeg\FFMpeg::create();
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.作为回应,我得到一个ErrorException,它只是声明:
Unable to load FFProbe
Run Code Online (Sandbox Code Playgroud)
这是没有意义的给我,我跑的时候ffmpeg,并ffprobe从我的Mac的终端,我可以看到他们正在安装.这显然是一个路径/解决问题,但我不确定如何解决它.有任何想法吗?
这都是在一个运行在localhost上的MAMP项目下托管的.
我面临的问题是,我有一个<span>包含多行文本且具有透明背景的内联文本。尽管有默认的行高,但文本上的背景重叠,导致背景覆盖在其自身上的较暗的水平行。
HTML:
<h1>
<span>Although it is set to a line height of 1, the background behind text still overlaps between rows.</span>
</h1>
Run Code Online (Sandbox Code Playgroud)
CSS:
h1 {
text-transform: uppercase;
font-family: Arial;
line-height: 1;
font-size: 30px;
background: rgba(0,0,0,0.5);
color: #FFF;
display: inline;
}
h1 span {
position: relative;
}
Run Code Online (Sandbox Code Playgroud)
span为display:inline-block不是一个可行的解决方案。line-height(或padding)并不是最佳答案,因为确切的字体渲染在浏览器和用户设置之间会发生变化。line-height例如,在 Chrome 中设置完美会在 Firefox 中产生不完美的结果。padding添加或删除以减少或增加文本与背景边缘之间的空间。angular ×4
javascript ×3
php ×3
html ×2
laravel ×2
mysql ×2
typescript ×2
coding-style ×1
css ×1
ffmpeg ×1
jquery ×1
knockout.js ×1
mysqli ×1
observable ×1
performance ×1
select ×1
sql ×1