我有这种情况,我分两步显示1个表格.因此,要进入表单的第二部分,您必须单击一个按钮.但在继续之前,我想执行表单验证(需要填写所有必填字段).但因为这是一个普通的按钮,所以不会触发整个提交魔法并且不会进行验证.所以我感兴趣的问题是如何在控制器中触发表单验证?触发特定字段的验证会更好.只是给出一个想法,表单看起来像
<form name="form" submit="save()">
<section id="step1">
<label for="username" required>Username</label>
<input type="text" name="username" ng-model="user.username" required />
.....
<button ng-click="proceed()">Proceed</button>
</section>
<section id="step2">
<label ...></label>
<input...>
....
<button type="submit">Save</button>
</section>
</form>
Run Code Online (Sandbox Code Playgroud)
另外,在所有必填字段都有效之前,我不想选择禁用该按钮.
我想在具有特定属性的最高值的集合中找到一个文档.
假设文档具有以下结构
{
_id: 'jswehfkwefkjw',
price: 10,
....
}
Run Code Online (Sandbox Code Playgroud)
如何选择价格最高的文档?
我找到了这个
transactions.find("id" => x).sort({"sellprice" => -1}).limit(1).first();
Run Code Online (Sandbox Code Playgroud)
但我无法将其转化为流星:(我现在看起来像这样
Articles.find({}, {sort: {price: -1}}).fetch();
Run Code Online (Sandbox Code Playgroud)
但这不行.有什么建议 ?
我刚刚将我的ipad mini更新到iOS 9.1并根据我可以使用我应该能够在我的设备上使用css snappoints进行safari.网上有快照点演示,但我写了一个我自己的(为什么不是:) DEMO.在该演示中,您可以水平滚动.
HTML:
<ol>
<li class="a"></il>
<li class="b"></il>
...
</ol>
Run Code Online (Sandbox Code Playgroud)
样式:
ol {
list-style-type: none;
white-space: nowrap;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
scroll-snap-type: mandatory;
scroll-snap-points-x: repeat(100%);
scroll-behavior: smooth;
}
Run Code Online (Sandbox Code Playgroud)
无论如何,我的演示在我的笔记本电脑上的FF和Safari中工作,但在我的iPad上却没有.所以问题是,我可以使用错误或者我做错了吗?
为角度材质2创建主题时,表示您可以设置以下颜色:主要,重音,警告前景和背景颜色.
但是你创建主题的方式只支持3种颜色/调色板:
$candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent, $candy-app-warn);
@include angular-material-theme($candy-app-theme)
Run Code Online (Sandbox Code Playgroud)
所以我的第一个问题是我如何定义一个主题foreground和background颜色?
是否也可以定义更多颜色?我可以用我的自定义组件,例如
我正在尝试将几个二进制字符串转换回int.但它没有转换我的所有二进制字符串,留下了java.lang.NumberFormatException异常.这是我的测试代码,带有3个二进制字符串:
public class Bin {
public static void main(String argvs[]) {
String binaryString ;
binaryString = Integer.toBinaryString(~0);
//binaryString = Integer.toBinaryString(~1);
//binaryString = "1010" ;
int base = 2;
int decimal = Integer.parseInt(binaryString, base);
System.out.println("INPUT=" + binaryString + " decimal=" + decimal) ;
}
}
Run Code Online (Sandbox Code Playgroud)
如果我转换"1010"它很有效,但是当我尝试转换其他两个中的一个时,我得到了异常.有人能解释一下为什么会这样吗?
干杯
我在变量中有一个函数的名称,但是所有内容都在一个闭包中.有了这个变量,我想调用函数,就像这样
(function(func) {
this[func]() ; // doesn't work
function bar() {}
function foo() {}
})('bar') ;
Run Code Online (Sandbox Code Playgroud)
这样的事情是可能的,或者我应该将函数添加到变量中,例如
(function(func) {
var ns = {
bar: function() {},
foo: function() {}
};
ns[func]() ; // OK
})('bar') ;
Run Code Online (Sandbox Code Playgroud) 如果您需要检查元素的悬停状态,可以按照此处的说明完成.问题是如果移动鼠标,则会松开状态.
在我的情况下,它的javascript提供悬停的视觉效果.因此,基本上问题与上述相同,但解决方案不适用.
如果您访问:http://volkshotel.nl/并将鼠标移到按钮/链接上,您将看到一个很好的故障效果.但很难检查.我已经提取了一个按钮
<span class="buzz">
<span class="buzz-original-text">Show me the way</span>
<span class="buzz-container"></span>
</span>
Run Code Online (Sandbox Code Playgroud)
现在,如果应用了毛刺效果,则会在buzz-container元素内部发生某些事情,但似乎无法检查该元素.Chrome内部有什么方法可以检查吗?
我用ES6编写了我的React应用程序.现在我想用ES6编写我的测试.所以这里的挑战是配置业力.
和谷歌一起,我带着karma.config.js走了这么远(我省略了配置文件的相同部分!):
...
files: [
'../node_modules/karma-babel-preprocessor/node_modules/babel-core/browser-polyfill.js',
'../app/**/*.jsx',
'../test/**/*.jsx'],
preprocessors: {
'app/**/*.jsx': ['react-jsx', 'babel'],
'test/**/*.jsx': ['react-jsx', 'babel']
},
'babelPreprocessor': {
options: {
sourceMap: 'inline'
},
filename: function(file) {
return file.originalPath.replace(/\.jsx$/, '.es5.js');
},
sourceFileName: function(file) {
return file.originalPath;
}
},
....
Run Code Online (Sandbox Code Playgroud)
我认为这个设置应该做什么:1)将JSX编译为JS,接下来babel应该将ES6转换为ES5.这与polyfill我预期的一起应该在phantomjs中运行.但不,这是我运行时来自业力的输出:
PhantomJS 1.9.8 (Mac OS X) ERROR
SyntaxError: Parse error
at Projects/ES6/app/js/app.jsx:35
PhantomJS 1.9.8 (Mac OS X): Executed 0 of 0 ERROR (0.027 secs / 0 secs)
[20:36:59] Karma has exited with 1
Run Code Online (Sandbox Code Playgroud)
第35行app.jsx包含实际的JSX部分.因此,出于某种原因,预处理器似乎并没有那么多.任何有关预处理器的帮助都会受到赞赏吗?
更新:我有这个几乎工作的nog.事实证明我应该像这样交换我的预处理器 …
单元测试角度指令并不是很难,但我发现有不同的方法可以做到这一点.
出于本文的目的,我们假设以下指令
angular.module('myApp')
.directive('barFoo', function () {
return {
restrict: 'E',
scope: true,
template: '<p ng-click="toggle()"><span ng-hide="active">Bar Foo</span></p>',
controller: function ($element, $scope) {
this.toggle() {
this.active = !this.active;
}
}
};
});
Run Code Online (Sandbox Code Playgroud)
现在我可以想出两种单元测试方法
方法1:
describe('Directive: barFoo', function () {
...
beforeEach(inject(function($rootScope, barFooDirective) {
element = angular.element('<bar-foo></bar-foo>');
scope = $rootScope.$new();
controller = new barFooDirective[0].controller(element, scope);
}));
it('should be visible when toggled', function () {
controller.toggle();
expect(controller.active).toBeTruthy();
});
});
Run Code Online (Sandbox Code Playgroud)
方法2:
beforeEach(inject(function ($compile, $rootScope) {
element = angular.element('<bar-foo></bar-foo>');
scope = $rootScope.$new();
$compile(element)(scope);
scope.$digest(); …Run Code Online (Sandbox Code Playgroud) 在Chrome的控制台中,这些天你可以写出相当不错的东西.查看此链接.我也做了一个截图:
正如您在屏幕截图中看到的那样,文件名/行号(VM298:4)写在右侧.是否有可能删除它,因为在我的情况下,这是一个非常长的名称,或多或少打破我试图在我的控制台中产生的效果?
javascript ×6
angularjs ×2
angular ×1
babeljs ×1
binary ×1
browser ×1
casting ×1
closures ×1
console.log ×1
css ×1
css3 ×1
forms ×1
html ×1
java ×1
karma-runner ×1
meteor ×1
react-jsx ×1
reactjs ×1
safari ×1
unit-testing ×1
validation ×1