可能,这是最简单的事情,但我无法在角度中解析字符串到Int ..
我想做什么:
<input type="text" ng-model="num1">
<input type="text" ng-model="num2">
Total: {{num1 + num2}}
Run Code Online (Sandbox Code Playgroud)
如何将这些num1和num2值相加?
日Thnx!
我有一个应用程序,使用mongodb和mongoose在node.js上工作.我的应用程序只是发送/删除/编辑表单数据,为此我有这样的猫鼬模型:
var mongoose = require('mongoose');
module.exports = mongoose.model('appForm', {
User_id : {type: String},
LogTime : {type: String},
feeds : [
{
Name: {type: String},
Text : {type: String},
}
]
});
Run Code Online (Sandbox Code Playgroud)
这工作得很好!
现在,我想在表单中添加一个函数,以便用户可以添加一个或多个字段来形成并在其中输入文本并发布.在客户端创建动态功能是没有问题的,但我知道我的mongoose.model必须正确构建.我的问题是:如何将该变量值(动态创建的表单数据名称及其文本)添加到mongoose模式?
我看到使用'strict:false'和'Schema.Types.Mixed'建议但我无法弄明白..我尝试过:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var feedSchema = new Schema({strict:false});
module.exports = mongoose.model('appForm', feedSchema);
Run Code Online (Sandbox Code Playgroud)
有小费吗?提前致谢!
我不知道如何测试组件方法是否在服务数据条件下被触发...
服务看起来像:
@Injectable()
export class SomeService {
someData() {
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
补偿:
export class SomeComponent {
constructor(private someService: SomeService) {
if (this.someService.someData()) {
this.someMethod();
} else {
console.log('keep kalm!');
}
}
someMethod() {
console.log('some method is fired!')
}
}
Run Code Online (Sandbox Code Playgroud)
测试:
describe('SomeComponent', () => {
let component: SomeComponent;
let fixture: ComponentFixture<SomeComponent>;
let mockSomeService = {
someData: () => true
}
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [SomeComponent],
providers: [
{
provide: SomeService, useValue: mockSomeService
}
]
})
.compileComponents();
}));
beforeEach(() …Run Code Online (Sandbox Code Playgroud) 在角度,我试图使用jQuery datepicker计算两个选定日期之间的天数.它只使用我正在使用的函数返回null.
但是我不太确定它是函数还是在angular中使用datepicker.看起来问题是函数,但是当我和jQuery一起使用它时它会起作用.
我的功能:
$scope.dayDiff = function(firstDate,secondDate){
$scope.dayDifference = parseInt(Math.round((secondDate - firstDate) / (1000 * 60 * 60 * 24)));;
}
Run Code Online (Sandbox Code Playgroud)
其余的:http://jsfiddle.net/1mzgLywe/5/
提前致谢!
我想在div中使用datePicker.我想在datePicker日历打开时扩展div的高度.
我有一个这样的div:
.dateBox{
width:160px;
height:auto;
border:1px solid blue;
}
Run Code Online (Sandbox Code Playgroud)
问题是当你点击datePicker输入并打开日历时,.datebox高度不会改变..我一直在玩,但我无法弄清楚...
我该如何解决这个问题?
直播:http://jsfiddle.net/fcrsznb1/2/
Thanx提前!
在我阅读关于这个主题的另一个问题的一些答案时:
我(猜)了解export和module.exports是什么以及如何使用它们!
我不明白的是为什么我们还需要出口,因为我们只使用module.exports就可以完美地解决问题.此外,如果我认为它很好:出口有可能产生错误.
例如:
// feature.js
function Person(name) {
this.name = name;
this.greet = function() {
console.log('Hi, my name is ' + this.name);
}
}
module.exports = Person;
// app.js
var Person = require(./feature);
var Aron = new Person('Aron');
Aron.greet(); // Hi, my name is Aron
Run Code Online (Sandbox Code Playgroud)
您可以使用导出简单地中断此工作版本:
exports = Person; // wont' work
exports.Person = Person; // still won't work (until you resolve it as new Person.Person('Aron') or ..require(..).Person) …Run Code Online (Sandbox Code Playgroud) 如果有掉毛问题,我希望 ng serve 停止。是否可以为此目的配置 Angular cli?
提前致谢!
我只是尝试验证字符串,如果它的前5个字符是数字,最后5个字符是字母:
我尝试过的:
var userId = "12345abcde";
// Get First and Second Five Characters
var firstFive = userId.substring(0, 5);
var secondFive = userId.substring(5, 10);
// get Global Letter and Nummers
var aStr = /[a-z, A-Z]/g;
var aNum = /[0-9]/g;
var c = userId.match(aNum);
// Try firstFive first...
if (firstFive === c) {
alert('yes');
} else {
alert('nop');
}
Run Code Online (Sandbox Code Playgroud)
这个警报nop.
这是因为firstFive是字符串而且c是对象吗?我的想法在哪里出错?
实例:http://jsfiddle.net/xe71dd59/1/
有小费吗?提前致谢!
angular ×2
angularjs ×2
jquery ×2
node.js ×2
angular-cli ×1
css ×1
datepicker ×1
jasmine ×1
javascript ×1
mongodb ×1
mongoose ×1
regex ×1
unit-testing ×1