简单的例子:我有一个textarea并希望为它提供额外的行为:在enterkey 上执行某些操作并转到下一行shift + enter
我想我应该提供额外的指令来添加该行为.我做到了这一点:http://jsbin.com/oruvuy/1/edit
PS一个hackie的东西对我来说似乎很奇怪:我$digest()手动调用.好吗?有什么想法吗?
JS:
angular.module('Chat', [])
.directive('enterSubmit', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var submit;
$(element).on({
keydown: function (e) {
submit = false;
if (e.which === 13 && !e.shiftKey) {
submit = true;
e.preventDefault();
}
},
keyup: function () {
if (submit) {
scope.$eval( attrs.enterSubmit );
// flush model changes manually
scope.$digest();
}
}
});
}
};
});
function ChatCtrl($scope) {
$scope.messages …Run Code Online (Sandbox Code Playgroud) 我正在使用CasperJS检查一些站点并将JSON数据写入文件.文件应写入public/data文件夹.但是当我试图casperjs 在我的项目目录(例如我的主目录)之外调用时,它直接写入文件~/public/data,而不是在我的项目目录中.
我该怎么解决这个问题?我还没有找到如何获取__dirname或__filename.
目前,针对问题/错误突出显示的eslint/tslint是超级不可见的(例如,比较Atom).几乎不可能发现问题 - 找到小绿色高亮区(见截图)
VSCode:

原子:

这种可能性存在吗?我们的网站不是一个页面,而是所有压缩的js文件application.js,我可以使用骨干路由器进行location.path解析吗?
我试试Backbone.history.start(pushState: true).它适用于我,但它是否正确?我只需要初始解析,而不是复杂的路由和重定向Backbone.Router.
高达angular2.beta15(包括)以下代码工作正常:
@Pipe({
name: 'isoDate'
})
export class ISODatePipe extends DatePipe implements PipeTransform {
transform(isoDate: string, args: any[]): string {
return super.transform(new Date(isoDate), args);
}
}
Run Code Online (Sandbox Code Playgroud)
在RC1上它不再工作了,即使我调整了管道语法:
@Pipe({
name: 'isoDate'
})
export class ISODatePipe extends DatePipe implements PipeTransform {
transform(isoDate: string, pattern?: string): string {
const date = new Date(isoDate);
return super.transform(date, pattern);
}
}
Run Code Online (Sandbox Code Playgroud)
我在浏览器中看到的消息如下:The pipe 'isoDate' could not be found.
如果我删除extends部分并返回一些字符串 - 它再次起作用.
发生了什么变化?
PS
目前已将其更改为
@Pipe({ name: 'isoDate' })
export class ISODatePipe implements PipeTransform …Run Code Online (Sandbox Code Playgroud) 我可以测试上传一个文件
attach_file 'photo', File.join(Rails.root, 'public', 'uploads', 'test.png')
Run Code Online (Sandbox Code Playgroud)
但是,如果我有一个带multiple属性的文件字段呢?如何使用Cucumber/Capybara测试多个文件上传?
我可以gruntjs在本地安装使用npm install grunt.
但是当我试图在全球范围内安装它时npm install grunt -g,我收到一个错误:
npm ERR! Error: EACCES, symlink '../lib/node_modules/grunt/bin/grunt'
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR!
npm ERR! System Linux 2.6.18-92.el5xen
npm ERR! command "nodejs" "/usr/bin/npm" "install" "grunt" "-g"
npm ERR! cwd /home/lj
npm ERR! node -v v0.6.18
npm ERR! npm -v 1.1.19
npm ERR! path ../lib/node_modules/grunt/bin/grunt
npm ERR! code EACCES
npm ERR! message EACCES, symlink '../lib/node_modules/grunt/bin/grunt'
npm ERR! errno {}
npm ERR! …Run Code Online (Sandbox Code Playgroud) 例如,我有一个经常需要执行的步骤,例如在某些测试之前用户登录.
如何为CasperJS编写可重用的代码块?他们扩展CasperJS的文档仅针对一个文件编写......
谢谢!
我有一个代码片段:
var app = angular.module('Demo', []);
app.controller('DemoCtrl', function ($scope) {
function notify(newValue, oldValue) {
console.log('%s => %s', oldValue, newValue);
}
$scope.$watch('collection.length', notify);
$scope.$watch('my', notify);
$scope.collection = [];
$scope.my = 'hello';
});
Run Code Online (Sandbox Code Playgroud)
$watch最初开火 此代码段将输出:
0 => 0
hello => hello
Run Code Online (Sandbox Code Playgroud)
这是正确的行为吗?当然,我可以检查值是否相等,但行为的原因是什么?
PS你可以在网上试试这个样本:http://jsbin.com/otakaw/7/edit
我想开始导航http://mysite.com/hello/world,而不是从站点根目录开始.
例如
$routeProvider
.when('/myurl', {
templateUrl: 'mytmpl.html',
controller: 'MyCtrl'
});
Run Code Online (Sandbox Code Playgroud)
应该在我的网址时做出反应 http://mysite.com/hello/world/myurl
我怎么能这样做?
javascript ×4
angularjs ×3
casperjs ×2
node.js ×2
angular ×1
backbone.js ×1
capybara ×1
coffeescript ×1
cucumber ×1
eslint ×1
gruntjs ×1
npm ×1
phantomjs ×1
tslint ×1
typescript ×1