我正在使用rack-cors gem在我的rails应用程序中实现CORS,但我不确定如何为不同的来源定义不同的资源.
我需要这样的东西:
config.middleware.insert_before 0, Rack::Cors do
allow do
origins 'http://localhost:3000'
resource '/api/*', headers: :any, methods: [:get, :post, :options, :put, :delete]
end
allow do
origins 'http://localhost:6000'
resource '*', headers: :any, methods: [:get, :post, :options, :put, :delete]
end
end
Run Code Online (Sandbox Code Playgroud)
所以它允许" http:// localhost:3000 "只访问'/ api/*'并允许' http:// localhost:6000 '访问所有.可能吗?
上面的代码是正确的代码/语法吗?
谢谢.
我正在尝试测试一个简单的标题组件,它有一个按钮,并且在聚焦时 - 仅使用 css 可见性属性打开一个下拉列表。
这是html:
<nav class="navigation">
<button type="button">
<span>click here</span>
</button>
<ul>
<li> Text </li>
<li> Text </li>
<li> Text </li>
</ul>
</nav>
Run Code Online (Sandbox Code Playgroud)
这是 scss 样式:
button {
span {
margin-right: 10px;
}
&:focus {
+ ul {
visibility: visible;
}
}
}
ul {
position: absolute;
list-style: none;
z-index: 1000;
visibility: hidden;
transition: visibility 0.1s linear;
background-color: $color-primary;
}
Run Code Online (Sandbox Code Playgroud)
这是测试:
it('should open dropdown on focus', () => {
let button = fixture.debugElement.query(By.css('button'));
button.triggerEventHandler('focus', null);
fixture.detectChanges();
let dropdownElement …Run Code Online (Sandbox Code Playgroud) unit-testing karma-jasmine angular2-testing typescript2.0 angular
我试图使边框变灰,并且由于某种原因,只有2个"边缘"/一半的盒子
<input type="text">是灰色的,而<textarea>边框很好.
知道为什么会这样吗?都有同一个班级.fill-form-style
.fill-form-font {
padding: 8px;
border-radius: 20px;
border-color: gray;
outline: none;
font-size: 16px;
}
Run Code Online (Sandbox Code Playgroud)
这是输入和textarea的HTML:
<input type="text" name="nickname" maxlength="22" size="25" class="fill-form-font">
<textarea name="content" cols="65" rows="10" style="resize: none;" class="fill-form-font"> Text Here </textarea>
Run Code Online (Sandbox Code Playgroud) 我有一个指令,根据它们$valid和$untouched属性验证表单内的输入 - 如果输入被"触摸",它会检查验证并相应地将字体和边框用红色/绿色着色,如果输入没有被"触及"它赢了什么都不做
我正在使用ngBootBox的自定义对话框,所以我没有type="submit"提交表单的按钮,我正在使用"创建"按钮的回调函数来传递/保存数据.
我的问题是,当我单击"创建"按钮并且表单不是"有效",因为某些字段为空 - 我的输入仍然是"未触及",因此该$watch函数未被调用.有解决方案吗 有没有办法做这样的事情:
$scope.createProjectForm.$setTouched(true);这将使该形式的所有子输入获得该值?
我也试过了,它没有用:
angular.forEach($scope.createProjectForm, function(field){
field.$setTouched(true);
});
Run Code Online (Sandbox Code Playgroud)
这是我的验证指令:
angular.module('mean.theme').directive("inputValidation", function () {
return {
restrict: 'EA',
require: 'ngModel',
link: function (scope, inputElement, attrs, ngModelCtrl) {
var $icon = $('<i class="fa"></i>');
inputElement.before($icon);
scope.$watchGroup([
function(){
return ngModelCtrl.$untouched;
},
function(){
return ngModelCtrl.$valid;
}
], function(Paramaters){
console.log(scope);
if(!Paramaters[0]) {
if (Paramaters[1]) {
inputElement.switchClass('validation-warning-border','validation-success-border',50)
inputElement.prev().switchClass('fa-warning validation-warning-font' , 'fa-check validation-success-font',50);
} else {
inputElement.switchClass('validation-success-border','validation-warning-border',50)
inputElement.prev().switchClass('fa-check validation-success-font','fa-warning validation-warning-font',50)
}
}
}); …Run Code Online (Sandbox Code Playgroud) angular ×1
angularjs ×1
border ×1
css ×1
forms ×1
html ×1
javascript ×1
rack-cors ×1
ruby ×1
unit-testing ×1