在其中,ng-pattern我们可以选择指定字段应匹配特定的模式。
我们如何指定它不匹配指定的模式?
例,
<input type="text" ng-pattern="/[*|\":<>[\]{}`()';@&$]/" />
Run Code Online (Sandbox Code Playgroud)
在这里,我不想字段匹配模式。相反,如果模式匹配,我想显示错误。
所以,我有一个由 Facebook 提供支持的 contenteditable div draft-js。我需要获得该 div 内插入符号的视觉位置,并且我实现了这个(适用于 Firefox 和 Chrome):
const selection = window.getSelection && window.getSelection();
if (selection.rangeCount > 0) {
const coordinates = selection.getRangeAt(0).getBoundingClientRect();
}
Run Code Online (Sandbox Code Playgroud)
在 Chrome 和 Firefox 中我得到了正确的坐标。然而,在 Firefox 中,我的所有位置属性都为 0。有什么解决方法/跨浏览器解决方案吗?
我有这个HTML div,它使用该ngMouseover指令通过函数从api获取一些数据,如下所示:
标记:
<div ng-mouseover="getData()">
</div>
Run Code Online (Sandbox Code Playgroud)
控制器:
$scope.getData = function() {
//get data from api
}
Run Code Online (Sandbox Code Playgroud)
有没有什么方法可以在ngMouseover指令中添加延迟,这样只有在光标在div上停留几秒后才会触发它?就像它debounce在里面一样ngModelOptions.
为了隐藏(但保留功能)文件对话框中丑陋的默认输入类型文件按钮,我使用了以下机制:
HTML:
<label for="file-input">
<i class="fa fa-edit"></i> <!-- acts as file input on click-->
</label>
<input type="file" id="file-input" />
Run Code Online (Sandbox Code Playgroud)
CSS:
#file-input {
display: none; //hide the file input
}
Run Code Online (Sandbox Code Playgroud)
这符合预期:我单击 font Awesome 编辑图标,然后弹出文件对话框。
但是,当我使用按钮时,它会停止工作。单击按钮时没有看到文件对话框:
<label for="file-input">
<button type="button">Upload file</button> <!-- not working-->
</label>
<input type="file" id="file-input" />
Run Code Online (Sandbox Code Playgroud) 我用nvd3.js创建简单的堆积条形图所描述这里
我在angular指令中添加了链接中提到的代码,如下所示:
app.directive('stackBar', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
nv.addGraph(function() {
var chart = nv.models.multiBarChart()
/*.transitionDuration(350)*/
.reduceXTicks(true) //If 'false', every single x-axis tick label will be rendered.
/*.rotateLabels(0) */ //Angle to rotate x-axis labels.
.showControls(true) //Allow user to switch between 'Grouped' and 'Stacked' mode.
.groupSpacing(0.1) //Distance between each group of bars.
chart.xAxis
.tickFormat(d3.format(',f'));
chart.yAxis
.tickFormat(d3.format(',.1f'));
d3.select(element[0])
.datum(exampleData())
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
//Generate some nice data.
function exampleData() {
return …Run Code Online (Sandbox Code Playgroud) 我是 Lodash 和函数式编程概念的新手。所以,我有一组具有每日日期的对象,如下所示:
[
{
"date": '1-Jan-2015',
"count": 4
},
{
"date": '4-Jan-2015',
"count": 3
},
{
"date": '1-Feb-2015',
"count": 4
},
{
"date": '18-Feb-2015',
"count": 10
}
]
Run Code Online (Sandbox Code Playgroud)
我想以这样的方式减少和聚合它,以便我得到一个对象数组,其中每个对象都有月度数据而不是像这样的逐日数据:
[
{
"date": 'Jan, 2015',
"count": 7 // aggregating the count of January
},
{
"date": 'Feb, 2015',
"count": 14 //aggregating the count of February
}
]
Run Code Online (Sandbox Code Playgroud)
目前,我编写了一个非常难读且复杂的代码,其中包含有效的 ifs 和 fors。但是,我想使用 lodash 重构它。可以使用lodash吗?我环顾四周,发现_.reduce和_.groupBy我大概可以使用,但我很为难,现在并不能想出一个好干净的实现。
所以我有一个动态设置的范围变量:
$scope.month = 'June'; //this will be a runtime assignment
Run Code Online (Sandbox Code Playgroud)
我有一个数组(示例),我必须使用ng-repeat迭代:
$scope.dates = ['12 June, 2015', '12 April, 2015', '13 May, 2015' ];
Run Code Online (Sandbox Code Playgroud)
这是标记:
<div ng-repeat = "date in dates">
{{date}}
</div>
Run Code Online (Sandbox Code Playgroud)
现在我想要实现的是在ng-repeat循环中,我只打印那些包含存储在$ scope.month中的月份的日期.如何使用过滤器执行此操作?
我试图理解 'stop' svg 元素的 offset 属性,但无法理解它。这是代码:
var vis = d3.select(scalecontainer)
.append("svg")
.attr('height', 30)
var gradient = vis.append("linearGradient")
.attr("y1", 0)
.attr("y2", 0)
.attr("x1", "0%")
.attr("x2", "100%")
.attr("id", "gradient")
.attr("gradientUnits", "userSpaceOnUse")
gradient
.append("stop")
.attr("offset", "0%")
.attr("stop-color", "red")
gradient
.append("stop")
.attr("offset","33%")
.attr("stop-color", "yellow")
gradient
.append("stop")
.attr("offset", "66%")
.attr("stop-color", "green")
var rect = vis.append("rect")
.attr("x", 10)
.attr("y", 10)
.attr("width", 100)
.attr("height", 20)
.attr("fill", "url(#gradient)");
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出:

难道不应该有“红色”、“黄色”和“绿色”三种不同的均匀间隔的颜色变化吗?我在这里做错了什么?
当我打印从MongoDB检索到的数据时,我得到以下输出:
[{"username": "ashish.mishra", "password": "hxMNwFOa", "frequency": "Daily", "name": "Ashish Mishra", "email": "ashish@mail.com"}]
Run Code Online (Sandbox Code Playgroud)
这是我检索它的方法:
user = db.UserData.find()
user = dumps(user)
print user //this is the printed version above
Run Code Online (Sandbox Code Playgroud)
我想访问每个键。我试过:
print user['username']
Run Code Online (Sandbox Code Playgroud)
和
print user[0]['username']
Run Code Online (Sandbox Code Playgroud)
它给了我错误:
TypeError: string indices must be integers, not str
Run Code Online (Sandbox Code Playgroud)
我知道有很多关于这些的线索,但到目前为止我还没有成功。知道如何做到这一点吗?