小编Ian*_*n S的帖子

作为@Input的子组件的角度传递回调函数

AngularJS有&参数,你可以将回调传递给指令(例如AngularJS的回调方式.是否可以将回调作为@InputAngular组件传递(如下所示)?如果不是,最接近什么是什么? AngularJS呢?

@Component({
    selector: 'suggestion-menu',
    providers: [SuggestService],
    template: `
    <div (mousedown)="suggestionWasClicked(suggestion)">
    </div>`,
    changeDetection: ChangeDetectionStrategy.Default
})
export class SuggestionMenuComponent {
    @Input() callback: Function;

    suggestionWasClicked(clickedEntry: SomeModel): void {
        this.callback(clickedEntry, this.query);
    }
}


<suggestion-menu callback="insertSuggestion">
</suggestion-menu>
Run Code Online (Sandbox Code Playgroud)

angularjs typescript angular

183
推荐指数
8
解决办法
18万
查看次数

Javascript/Ember - 切换变量的布尔值

我知道有.set()方法将布尔值设置为true或false但我想知道是否有类似.set()的方法,除非它切换布尔值.

在这种情况下,布尔值isEditing被设置为"true".

isEditing:false,
actions: {
  edit: function(category){
    category.set('isEditing', true);
    console.log(this.get('isEditing'))
  },
}
Run Code Online (Sandbox Code Playgroud)

这是html

{{#if isEditing}}
  <div class="category-text"> 
    {{view Ember.TextField valueBinding=name action="turnOffEditMode"}}
  </div>
{{else}}
  <div class="category-text"> 
    {{#linkTo 'category' this}}
      {{name}}
    {{/linkTo}}
  </div>
{{/if}}  
Run Code Online (Sandbox Code Playgroud)

javascript html5 boolean toggle ember.js

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

:hover 在 ios 移动设备上变成双触摸而不是悬停

首先,这不是以下内容的克隆:iPad/iPhone 悬停问题导致用户双击链接, 因为我想要一个纯 CSS 的答案。此链接中的所有答案都需要 js 或 jQuery,而一个 CSS 答案涉及背景图像。我正在尝试更改不透明度,仅此而已。

CSS 想要将自己推向移动革命,但我看到的用于创建悬停效果的简单“touchDown”(又名触摸悬停)的每个解决方案都需要 javascript 或 jQuery。

下面是一些简单的代码来说明我的意思:

.btn {
  border-radius: 5px;
  display: block;
  opacity: 1; <--from
  background: red;
  text-align: center;
  line-height: 40px;
  font-weight: bold;
  &:hover {
    opacity:.7; <--to
    transition: opacity .2s ease-out; <--fun fade animation :)
    -moz-transition: opacity .2s ease-out;
    -webkit-transition: opacity .2s ease-out;
    -o-transition: opacity .2s ease-out;
  }
}
Run Code Online (Sandbox Code Playgroud)

在 Chrome 和 Safari 中测试

css hover touch ios

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

某些量角器 API 函数会导致错误

为什么在使用 Protractor API 函数时会收到错误消息?我在互联网上搜索了这个问题的解决方案,我找到了几个类似的答案,但它们没有用,所以我问社区。

我正在尝试使用 Karma 和 Protractor 设置最简单的 e2e 测试。像这样的空测试代码块不会产生错误:

describe('Mapping Assistant State', () => {
   beforeEach(() => {
   });

   it('should display a table',() => {
      console.log('test');
   });

   it('should click the create Paste button',() => {

    });
});
Run Code Online (Sandbox Code Playgroud)

一旦我从量角器中添加了某些函数,如expect() 或browser(),就会出现问题:

it('should display a table',() => {
    browser.get('someUrl');
    expect(element(by.css('.map')).getText()).toContain('map');

});
Run Code Online (Sandbox Code Playgroud)

以下是我的 package.json 的一些内容:

"protractor": "^5.3.0",
"karma": "^1.7.1",
"@angular/cli": "^1.6.6",
"typescript": "^2.5.2"
"@angular/core": "^4.3.6",
"rxjs": "^5.4.3",
"@types/selenium-webdriver": "^3.0.6",
"ts-node": "^4.0.1",
"@types/node": "^8.0.58",
Run Code Online (Sandbox Code Playgroud)

还:

import { browser, by, element } from 'protractor'; …
Run Code Online (Sandbox Code Playgroud)

karma-runner protractor karma-jasmine e2e-testing angular

5
推荐指数
4
解决办法
7831
查看次数

从浏览器中的当前位置滚动距离后检测滚动

我想检测我是否正在滚动,但仅在我从当前位置滚动一定距离后才检测。当我停止滚动时,此距离重置为当前位置

我知道如何使用 检测滚动经过页面上的某个点.scrollTop(),但我希望这个特定点成为我当前的位置,但只有在我停止滚动之后。

为什么我需要这个:我有一个导航栏,它可以根据我是否向上或向下滚动来更改所有CSS。因此,如果我的滚动手指向不同方向颤抖(例如从上到下滚动),导航栏将像闪光灯一样变换。所以我的计划是仅检测高于或低于 10px 的滚动,因此用户需要制作专用滚动来激活导航栏 css 更改。

伪代码:

if (scrolled 10px above or below current_location in browser) {
  console.log('it worked');
} else {
  console.log('You have not scrolled far enough!')
}

if (scrolling stops) {
  reset position of current_location. 
}
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery scroll

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

浏览器选项卡知道它何时被复制

我希望我的浏览器选项卡知道它何时被复制。

我见过的唯一类似的解决方案只关注知道它已被重复的重复选项卡或知道它已被重复的原始选项卡,但这仅适用于 Chrome。

要求:

  • 解决方案适用于所有现代浏览器

奖金如果解决方案:

  • 适用于 Internet Explorer 版本
  • 使用一些原生 Angular 功能

javascript duplicates browser-tab typescript angular

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

Hartl Rails教程的用户#index中的ArgumentError

当我尝试查看用户索引时,我一直遇到错误.这是Hartl的Ruby on Rails教程(一个优秀的教程)的第9章

错误的参数数量(2为1)

<li>
  <%= gravatar_for user, size: 52 %>
  <%= link_to user.name, user %>
  <% if current_user.admin? && !current_user?(user) %>
    | <%= link_to "delete", user, method: :delete,
                                  data: { confirm: "You sure?" } %>
  <% end %>
</li>
Run Code Online (Sandbox Code Playgroud)

我不知道为什么它认为第2行认为我在调用2个参数.

ruby ruby-on-rails railstutorial.org

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

Emberjs - 将{{input}}过滤条与我的对象列表相关联.在我输入时,列表会过滤

我正在尝试将此过滤搜索栏的工作示例http://jsbin.com/AViZATE/37/edit与我自己的项目合并.搜索栏似乎没有连接到我的对象列表.:(

让我告诉你我做了什么.

App.RecordCategoriesController = Ember.ArrayController.extend({
    searchResult: function(){
        var searchTerm = this.get('searchTerm');
        var regExp = new RegExp(searchTerm,'i');
        this.get('model').set('content',this.store.filter('recordCategory',function(item){
            return regExp.test(item.get('categoryName'));
        }));
    }.observes('searchTerm'),
});
Run Code Online (Sandbox Code Playgroud)

正如您在上面所看到的,我已将' todo'与' recordCategory'和' title'替换为' categoryName'.到目前为止似乎很好.'

在record_categories.hbs中,我创建了将用于过滤的输入栏.

{{input type="text" id="search-todo" placeholder="Search Todo List..." value=searchTerm}}
Run Code Online (Sandbox Code Playgroud)

然后在它下面,#each把手循环并显示我的列表

{{#each itemController="recordCategory"}}
  <li>{{categoryName}}</li>
{{/each}}
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?我注意到searchResults似乎没有在他们的示例中的任何其他地方调用

这也是我的路线,因为为什么不.

App.RecordCategoriesRoute = Ember.Route.extend({     
    model: function() {
        VpcYeoman.RecordCategories.FIXTURES=[];
        $.ajax({
            url: '/recordCategories',
            dataType: 'json',
            type:"get",      
            async: false,
            success : function(data, textStatus, xhr) { 
                if(xhr.status==200){
                    VpcYeoman.RecordCategories.FIXTURES=data;
                }
            }
        });
        return this.store.find('recordCategories');
    }
}); 
Run Code Online (Sandbox Code Playgroud)

javascript model-view-controller filtering handlebars.js ember.js

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

怎么做:n-last-child(1 + odd)

我想做一些类似的事情nth-last-child(1 + odd),最后一个孩子受到影响,但只有元素是奇数.

nth-last-child(1 + odd) 虽然不起作用,所以我该怎么办?


奖金:一个更灵活的答案,允许我抓住最后一个孩子,只有它是奇怪的和奇怪的孩子在它之前.

<ul>
  <li>not effected</li>
  <li>not effected</li>
  <li>not effected</li>
  <li>not effected</li>
  <li>affected</li>
  <li>not effected</li>
  <li>affected</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

但如果最后一个孩子即将到来,则没有任何反应,所以:

<ul>
  <li>not effected</li>
  <li>not effected</li>
  <li>not effected</li>
  <li>not effected</li>
  <li>not effected</li>
  <li>not effected</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

css css-selectors css3

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