假设我们想在angular2中使用某个库中的组件(例如来自material2).组件注释如下所示:
@Component({
moduleId: module.id,
selector: 'md-input',
templateUrl: 'input.html',
styleUrls: ['input.css'],
providers: [MD_INPUT_CONTROL_VALUE_ACCESSOR],
host: {'(click)' : 'focus()'}
})
Run Code Online (Sandbox Code Playgroud)
该组件附带"默认"样式表,即"input.css".如果我们在应用程序中使用此组件,我们可能希望覆盖/扩展某些样式,而无需复制和操作组件本身.这该怎么做?
可能的解决方案1:将封装设置为"ViewEncapsulation.None":
这不是一个真正的解决方案,只是一种解决方法.
可能的解决方案2:在CSS中使用":: shadow"或"/ deep /":
也可以使用,但根据WebComponent规范不推荐使用它.
可能的解决方案3:使用全局CSS并覆盖组件CSS:
也可以,但它违反了shadow DOM概念.
可能的解决方案4:直接在父组件的模板中覆盖:
例:
<my-cmp [font-size]="100"></my-cmp>
Run Code Online (Sandbox Code Playgroud)
如果我们做了很多重写,那真的不合适.
可能的解决方案5:以某种方式用一个额外的样式表覆盖或扩展"@Component"定义:
这似乎是唯一正确的解决方案(至少对我而言).但我不知道该怎么做......
有什么建议吗?也许我弄错了...谢谢.
我正在尝试测试未登录用户的行为如何
describe "not logged in user" do
user_no_rights
it "can't access action index" do
expect(get :index).to raise_error(CanCan::AccessDenied)
end
end
Run Code Online (Sandbox Code Playgroud)
我运行rspec时的输出
Failure/Error: expect(get :index).to raise_error("CanCan::AccessDenied:You are not authorized to access this page.")
CanCan::AccessDenied:
You are not authorized to access this page.
Run Code Online (Sandbox Code Playgroud)
所以它看起来像是正确的execption,但为什么规范不通过?
我们试图将一个字符串数组'连接'到聚合内的单个字符串.
给出以下数据集:
收集1:
{
id: 1234,
field: 'test'
}
Run Code Online (Sandbox Code Playgroud)
收集2:
{
id: 1111,
collection1_id: 1234,
name: 'Max'
},
{
id: 1112,
collection1_id: 1234,
name: 'Andy'
}
Run Code Online (Sandbox Code Playgroud)
当前结果(查找后等):
{
id: 1234,
field: 'test',
collection2: ['Max', 'Andy']
}
Run Code Online (Sandbox Code Playgroud)
期望的结果:
{
id: 1234,
field: 'test',
collection2: 'Max, Andy'
}
Run Code Online (Sandbox Code Playgroud)
是否有可能将'collection2'加入单个字符串?我们尝试过,$concat但它只接受字符串.
我正试图通过轮胎/弹性搜索来实现"范围式"功能.为什么这不起作用,即使我的状态为"Test1"或"Test2"的条目?结果总是空的.
collection = @model.search(:page => page, :per_page => per_page) do |s|
s.query {all}
s.filter :terms, :status => ["Test1", "Test2"]
s.sort {by :"#{column}", "#{direction}"}
end
Run Code Online (Sandbox Code Playgroud)
没有过滤器,该方法工作正常.过滤方法有问题吗?!我检查了轮胎doku ....它应该工作.
谢谢!:)