小编cam*_*kid的帖子

PHP手册OOP可见性示例 - 有人可以解释它

我在PHP OOP手册http://www.php.net/manual/en/language.oop5.visibility.php中看到了这个,我无法理解为什么输出不是:Foo :: testPrivate Foo: :testPublic

class Bar 
{
    public function test() {
        $this->testPrivate();
        $this->testPublic();
    }

    public function testPublic() {
        echo "Bar::testPublic\n";
    }

    private function testPrivate() {
        echo "Bar::testPrivate\n";
    }
}

class Foo extends Bar 
{
    public function testPublic() {
        echo "Foo::testPublic\n";
    }

    private function testPrivate() {
        echo "Foo::testPrivate\n";
    }
}

$myFoo = new foo();
$myFoo->test(); // Bar::testPrivate 
                // Foo::testPublic
Run Code Online (Sandbox Code Playgroud)

php oop

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

错误:未找到MyAppComponent的模板

我遵循了Angular 2快速入门指南,但收到以下错误:

在实例化令牌(AppView)期间出错!ORIGINAL ERROR:错误:找不到MyAppComponent的模板

这是相关代码:

import {Component, View} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser'
// Note I've changed Template to View here as I think it is a typo

....

@View({
  template: '<h1>Hello {{ name }}</h1>'
})

....
Run Code Online (Sandbox Code Playgroud)

遵循Duncan Booth的建议http://blog.ionic.io/angular-2-series-introduction/我做了以下更改,一切正常:

import {Component, Template} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';

....

@Template({
    inline: "<h1>Hello {{ name }}</h1>"
})

....
Run Code Online (Sandbox Code Playgroud)

但在相同的链路yesimahuman的评论中提到,"观是新的语法",这似乎是这种情况如所示Plunker角2分步指南.

那么为什么Quickstart代码会抛出错误,什么是正确的修复?

angularjs

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

如何禁用点击手风琴组标题?

这里的手风琴示例的缩减版本.

  <accordion>
    <accordion-group heading="Static Header">
      This content is straight in the template.
    </accordion-group>
  </accordion>
Run Code Online (Sandbox Code Playgroud)

如何禁用单击手风琴组标题.我在accordion元素和accordion-group元素上尝试了ng-disabled = true但它不起作用.

angularjs angular-ui-bootstrap

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

是否可以在$ routeProvider声明中访问$ routeParams对象?

在以下代码中:

phonecatApp.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/phones', {
        templateUrl: 'partials/phone-list.html',
        controller: 'PhoneListCtrl'
      }).
      when('/phones/:phoneId', {
        templateUrl: 'partials/phone-detail.html',
        controller: 'PhoneDetailCtrl'
      }).
      otherwise({
        redirectTo: '/phones'
      });
  }]);
Run Code Online (Sandbox Code Playgroud)

是否有可能以某种方式访问​​templateURL中的'phoneId'值,例如这样的东西(我知道它不起作用,但它是为了解释我在问什么):

      when('/phones/:phoneId', {
        templateUrl: 'partials/' + $routeParams.phoneId + '.html',
        controller: 'PhoneDetailCtrl'
      }).
Run Code Online (Sandbox Code Playgroud)

目的是加载以phoneId命名的HTML文件.

angularjs

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

通用类型'CanDeactivate <T>'需要1个类型的参数

在下面的代码中("使用TypeScript进行Angular 2开发"一书中的示例):

import {CanDeactivate, Router} from "@angular/router";
import {Injectable} from "@angular/core";

@Injectable()
export class UnsavedChangesGuard implements CanDeactivate{

    constructor(private _router:Router){}

    canDeactivate(){
        return window.confirm("You have unsaved changes. Still want to leave?");

    }
}
Run Code Online (Sandbox Code Playgroud)

当我将鼠标悬停在WebStorm中的CanDeactivate上时,我看到一个警告:

在此输入图像描述

参考这个问题的答案 - 通用类型'Observable <T>'需要1个类型参数 - 以下更改将删除警告:

export class UnsavedChangesGuard implements CanDeactivate<any>{
Run Code Online (Sandbox Code Playgroud)

但是,我想知道如何找出CanDeactivate所需的实际参数.

编辑:看@ angular/router/src/interfaces.d.ts,我们可以看到以下内容:

/**
 * @whatItDoes Indicates that a class can implement to be a guard deciding if a route can be
 * deactivated.
 *
 * @howToUse
 *
 * ```
 * class UserToken {}
 * …
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

将任何值为空字符串的对象字段替换为 null 而无需迭代?

考虑这个对象:

{
    value1: 'bacon',
    value2: '',
    value3: 'lard',
    value4: '',
    value5: 'cheese',
};
Run Code Online (Sandbox Code Playgroud)

有没有办法在不迭代的情况下获得以下对象?:

{
    value1: 'bacon',
    value2: null,
    value3: 'lard',
    value4: null,
    value5: 'cheese',
};
Run Code Online (Sandbox Code Playgroud)

typescript

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

如何调用脚本标签中定义的 javascript 函数?

例子:

<script type="text/javascript">
    function test() {
        console.log("Hello world");
    }
</script>
Run Code Online (Sandbox Code Playgroud)

我该怎么称呼test()

编辑:我没有正确解释这一点。

我正在使用 node.js 的请求模块来加载包含 javascript 函数的外部 html 文件:

request.get(options, function (error, response, body) {
    if (error && response.statusCode !== 200) {
    }
    else {
        jsdom.env({
            html: body,
            scripts: ["../jquery-1.6.4.min.js"]
        }, function (err, window) {
            var $ = window.jQuery;
Run Code Online (Sandbox Code Playgroud)

我只是在寻找在“body”中调用函数的语法。

javascript node.js jsdom

-2
推荐指数
1
解决办法
4971
查看次数