我有一个项目,我grunt用来处理我Js和SASS文件.
目前,当我需要处理某些内容时,gruntfile.js即使我只想更改一个模块或仅更改SASS文件,我也需要调用我内部的所有任务.
有没有办法创建自定义任务,只运行sass部分,另一个只创建模块进程,我可以从提示中调用此任务?
这是我尝试过的,没有成功:
module.exports = function(gruntHome) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
/* @CONCAT */
concat: {
home : {
src: 'src/app/component/home/*.js',
dest: 'src/app/component/home/concat/concat_config.js'
}
},
/* @ANNOTATE */
ngAnnotate: {
options: {
add: true
},
home: {
files: {
'src/app/component/home/concat/concat_config.js': 'src/app/component/home/concat/concat_config.js'
}
}
},
/* @UGLIFY */
uglify: {
home: {
src: 'src/app/component/home/concat/concat_config.js',
dest: 'app/component/home/home.min.js'
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-ng-annotate');
grunt.registerTask('gruntTask', ['concat', 'ngAnnotate', 'uglify']);
};
Run Code Online (Sandbox Code Playgroud)
如果不可能,还有其他方法可以实现这一目标吗?因为我的gruntfile.js很大,有时需要花费很多时间来处理,即使我不需要处理所有内容.
这里的链接 …
我知道关于这个问题还有其他问题,但我已经准备了 10 多个答案并尝试了每一个,但没有一个对我有用。
我收到此错误:Uncaught ReferenceError: require is not defined当我尝试加载外部纯 javascript 文件以在 JWT 中进行编码时。
这是我试图包含的文件require():https : //github.com/hokaccha/node-jwt-simple我用npm.
在我的代码中,我尝试了很多东西。
main.js与 grunt 的联系中;<head>用<script src="path/to/folder"></script>;在里面手动加载通过所有这些尝试,我遇到了相同的错误。我究竟做错了什么?
这是我现在使用的代码:
索引.html
<head>
<script type="text/javascript" src="dist/js/angular.min.js"></script>
<script type="text/javascript" src="dist/js/ui-router.min.js"></script>
<script type="text/javascript" src="dist/js/jwt.js"></script>
[... rest of head ...]
Run Code Online (Sandbox Code Playgroud)
appCtrl.js(稍后将在构建中与应用程序的其余部分连接)
.controller('MainCtrl',
['$rootScope', '$scope', '$state',
function($rootScope, $scope, $state) {
var jwt = require('jwt');
var payload = { foo: 'bar' }; …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用其他元素中的角度ng-click在我的input元素中触发click事件,如下所示:
HTML
<div class="myClass" ng-click="vm.selectImage()" nv-file-drop uploader="vm.uploadImage">
Drop your image here
</div>
<div ng-hide="!hideInput">
<input type="file" id="imgSelect" nv-file-selec uploader="vm.uploadImage" />
</div>
Run Code Online (Sandbox Code Playgroud)
调节器
vm.selectImage= selectImage;
function selectImage() {
angular.element('#imgSelect').trigger('click');
};
Run Code Online (Sandbox Code Playgroud)
我知道还有其他类似的问题,但我试图使用他们所说的(其中一组显示我正在使用的相同代码),例如:
但即便如此,甚至使用这样的指令:
.directive('selectImg', selectImg);
function selectImg() {
return {
restrict: 'A',
link: function(scope, element) {
element.bind('click', function(e) {
//option 1
angular.element(e.target).siblings('.imgSelect').trigger('click');
//option 2
angular.element( document.querySelector( '#imgSelect' ) ).trigger('click');
//option 3
var myEl = angular.element( document.querySelector( '#imgSelect' ) );
myEl.trigger('click');
//option 4
angular.element('#imgSelect').trigger('click'); //angular way
}); …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Angular 5函数上使用debounceTime,但不确定如何使用它。构建搜索功能时,可以使用它,因为它绑定到对该输入值所做的更改,如下所示:
this.search
.debounceTime(400)
.distinctUntilChanged()
.takeUntil(this.onDestroy)
.subscribe((model) => {
return this.filterArray(model);
});
Run Code Online (Sandbox Code Playgroud)
但是现在我想将其应用于一个函数,该函数在很多地方都被调用过,并通过http post将事件发送到数据库,如下所示:
private saveData(): void {
this.http.post('event/url', data).takeUntil(this.onDestroy).subscribe((response: Response) => {
// -
}, error => {
// -
});
}
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?saveData().debounceTime()还是我需要以其他方式做到这一点?
我正在尝试使用AngularJs 1.5组件,但每次我声明bindings我一直收到此错误:
与'homeComp'一起使用的属性'message'中的表达式'undefined'是不可赋值的!
我正在尝试一个简单的组件,只是为了学习它,这是代码:
var component = {
bindings: {
message: '='
},
controllerAs: 'vm',
controller: function MainController() {
this.message = 'Welcome to my component';
function debug() {
this.message = 'This message changed';
}
this.debug = debug;
},
template: [
'Message: {{ vm.message }}<br />',
'<button ng-click="vm.debug()">Change message</button>'
].join(``)
};
Run Code Online (Sandbox Code Playgroud)
你可以在这里看到错误:http://plnkr.co/edit/uutk5kxOVpa5eLfjoa8U?p = preview
代码有什么问题?或者是什么导致了这个错误?如果我删除绑定,则不会出现错误,我可以更改消息.
我试图在我的减速器上使用 Object Spread 和 @ngrx 以及 Angular 和 TypeScript,但是,我不断在控制台中收到此错误:
引用错误:__assign 未定义
这是我的代码:
case INCREMENT: {
return state = {
...state,
counter: state.counter++
}
}
Run Code Online (Sandbox Code Playgroud)
但如果我按照下面的代码执行,我可以很好地运行代码:
case INCREMENT: {
return Object.assign({}, state, {
counter: state.counter++
}
}
Run Code Online (Sandbox Code Playgroud)
我在另一个问题中读到这可能与打字稿版本有关,但我正在使用"typescript": "~2.2.1".
我错过了什么吗?
编辑:
按照评论中的要求添加 tsconfig.js。
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmitHelpers": true,
"noEmitOnError": true,
"lib": [
"es6",
"dom",
"es2015.iterable"
],
"baseUrl": ".",
"paths": {
"*": [
"./node_modules/tns-core-modules/*",
"./node_modules/*"
]
}
},
"exclude": [
"node_modules", …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Angular中测试一个接收日期的服务函数,并检查该日期是否为将来的日期。如果是,则返回true。
// The 'check_date' will always be in the format `dd/mm/yyyy`
public checkDate(check_date: string): boolean {
const today: any = new Date();
const dateParts: any = check_date.split('/');
const dateObject: any = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]);
if (dateObject.getTime() > today.getTime()) {
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我该如何测试?因为如果我做这样的事情:
it('should return true if date is in the future', () => {
const date = '04/02/2018';
const result = service.checkDate(date);
expect(result).toBeTruthy();
});
Run Code Online (Sandbox Code Playgroud)
今天它将过去,因为new Date()将会过去01/02/2018。但是,如果我下个月运行此测试,它将无法通过。
我可以将日期设置为将来要测试的日期,例如01/01/3018。但是我想知道是否还有另一种方法可以测试这种情况。
我在这里遇到了一些问题.我为此尝试了很多不同的修复,但似乎都没有.我想在另一个div的中间对齐div的内容.
我想只使用auto或%值,因为我想让网站也用于移动设备.
这是我到目前为止的代码:http://codepen.io/anon/pen/xHpaF/ 我想让那些红色框与包装div的中心对齐.
如果有人可以帮助我.谢谢!
我有一个对象数组,我想根据对象属性值对其进行过滤。我想通过不同的属性对其进行过滤,因此它必须是动态的。为此,我有一个输入字段,在其中输入然后过滤数组。因此,假设我有以下两个不同的数组:
const array_one = [
{id: 1, code: 'ABC123', name: 'John'},
{id: 2, code: 'DEF456', name: 'Stew'},
// ...
];
const array_two = [
{id: 1, value: '012345', company: 'Company 01' },
{id: 2, value: '678910', company: 'Company 02' },
// ...
];
Run Code Online (Sandbox Code Playgroud)
我想要一个可以基于过滤第一个数组的函数name,如果我想过滤第二个数组,也想通过过滤它value。
为此,我构建了以下功能:
filterArray(array: Array<any>, fields: Array<any>, value: string) {
value = this.convertString(value);
array = array.filter((item) => {
fields.forEach(obj => {
if ( item[obj] ) {
const _newObj = this.convertString(item[obj]);
if ( _newObj.indexOf(value) !== …Run Code Online (Sandbox Code Playgroud) 我有一个带有 FormAwway 的表单,其中显示了所购买的产品,这是我的组件:
constructor() {
this.purchaseForm = new FormGroup({
id: new FormControl(null, Validators.required),
purchase: new FormControl(null, Validators.required),
date: new FormControl(null, Validators.required),
products: new FormArray([]),
});
}
public createNewLine(object: any = {}): FormGroup {
const newLine = new FormGroup({
index: new FormControl(null),
id: new FormControl(object.id, Validators.required),
id_product: new FormControl(object.id_produto, Validators.required),
quantity: new FormControl(object.quantidade, Validators.required),
value_unit: new FormControl(object.valor_unitario, Validators.required),
value_total: new FormControl(object.valor_total, Validators.required),
});
const formArray = <FormArray>this.purchaseForm.get('products');
newLine.get('index').patchValue(formArray.length);
newLine.valueChanges.pipe(debounceTime(400)).subscribe(value => this.updateProductValue(value));
return newLine;
}
private updateProductValue(object): void {
const quantity = …Run Code Online (Sandbox Code Playgroud) javascript ×4
angular ×3
angularjs ×3
node.js ×2
typescript ×2
arrays ×1
css ×1
filter ×1
gruntjs ×1
html ×1
ngrx ×1
ngrx-store ×1
rxjs ×1
unit-testing ×1