使用AngularJS,我可以使用ng-pristine或ng-dirty检测用户是否已进入该字段.但是,我想在用户离开字段区域后才进行客户端验证.这是因为当用户输入电子邮件或电话等字段时,他们将始终收到错误,直到他们完成输入完整的电子邮件,这不是最佳的用户体验.
更新:
Angular现在附带自定义模糊事件:https: //docs.angularjs.org/api/ng/directive/ngBlur
我正在使用 aiohttp 发出异步请求,我想测试我的代码。我想模拟 aiohttp.ClientSession 发送的请求。我正在寻找类似于响应处理requestslib模拟的方式。
我如何模拟aiohttp.ClientSession?
# sample method
async def get_resource(self, session):
async with aiohttp.ClientSession() as session:
response = await self.session.get("some-external-api.com/resource")
if response.status == 200:
result = await response.json()
return result
return {...}
# I want to do something like ...
aiohttp_responses.add(
method='GET',
url="some-external-api.com/resource",
status=200,
json={"message": "this worked"}
)
async def test_get_resource(self):
result = await get_resource()
assert result == {"message": "this worked"}
Run Code Online (Sandbox Code Playgroud)
编辑
我在几个项目中使用了https://github.com/pnuckowski/aioresponses,它非常适合我的需求。
我正在解决以下问题: 编写一个程序,其中第一个参数是"sum","product","mean"或"sqrt"之类的单词,以及一系列数字的进一步参数.该程序将适当的功能应用于该系列.
我已经解决了它(下面的代码)但它体积庞大且效率低下.我想重写它有一个功能计算器,调用其他功能(即功能和,功能产品).
我的问题:我如何编写函数sum,product,sqrt等,所以当函数计算器调用时,它们正确地采用计算器的参数并计算数学.
下面是庞大的代码:
function calculator() {
var sumTotal = 0;
var productTotal = 1;
var meanTotal = 0;
var sqrt;
if(arguments[0] === "sum") {
for(i = 1; i < arguments.length; i++) {
sumTotal += arguments[i];
}
return sumTotal;
}
if(arguments[0] === "product") {
for(i = 1; i < arguments.length; i++) {
productTotal *= arguments[i];
}
return productTotal;
}
if(arguments[0] === "mean") {
for(i = 1; i < arguments.length; i++) {
meanTotal += …Run Code Online (Sandbox Code Playgroud) (AngularJS v1.2.0-rc.3 + Angular UI-Router v0.2.0)
在我的index.html,我有以下代码:
<div class="container" ui-view></div>
Run Code Online (Sandbox Code Playgroud)
在我的app.js中,我有以下代码:
$stateProvider
.state('projects', {
abstract: true,
url: '/projects',
template: '<ui-view />',
})
// below display properly
.state('projects.list', {
url: '',
templateUrl: 'views/project_list.html',
controller: 'ProjectListCtrl'
})
// below display properly
.state('projects.one', {
url: '/{projectId:[0-9]{1,8}}',
templateUrl: 'views/project_dashboard.html',
controller: 'ProjectCtrl'
})
// below does not display at all
.state('projects.one.campaigns', {
url: '/campaigns',
template: 'I cannot seem to display this text'
})
Run Code Online (Sandbox Code Playgroud)
我可以打下面的路线就好了:index.html/projects,index.html/projects/1,但我不能打这个路线:index.html/projects/1/campaigns
有谁知道为什么我不能?
如果您可以回答我如何在与projects.one.campaigns州相同的URL页面上显示状态,则可以获得奖励积分 …
JS在这里:http://jsfiddle.net/TegFf/73/
从这个答案,我了解Angular 1.2附带启用严格上下文转义(SCE).这会影响使用ng-srcHTML5视频的表达式解析器.我知道,如果我环绕$sce.trustAsResourceUrl(videoURL)每个视频源,那么Angular将正常播放它们.但是,我从API获取了一个视频源列表.循环遍历数组中的项目,将每个源分配为a $sce.trustAsResourceUrl,然后在我的视图中循环遍历该新数组,这对我来说很昂贵.
将所有视频源分配为受信任的最有效方法是什么,而不必遍历所有视频源?我可以$sce预先指定所有视频资源吗?
我的目标是将最新的git commit附加到我的index.html文件中.
以下任务成功返回最新的git哈希(使用gulp-git):
var git = require('gulp-git');
gulp.task('hash', function() {
git.revParse({args:'--short HEAD'}, function (err, hash) {
return hash;
});
});
Run Code Online (Sandbox Code Playgroud)
以下任务构建我的HTML:
var inject = require('inject-string');
gulp.task('html', function () {
return gulp.src('app/index.html')
.pipe(inject.append('append git hash here!'))
.pipe(gulp.dest('dist'))
});
Run Code Online (Sandbox Code Playgroud)
这成功地附加了一个字符串,index.html但是如何将hash任务的返回值注入html?
angularjs ×3
javascript ×2
aiohttp ×1
forms ×1
git ×1
gulp ×1
gulp-inject ×1
html5 ×1
video ×1