AngularJs formatting date - angularjs

I am not sure what's wrong with my date formatting.
I receive the following error:
Error: [ngModel:nonassign] http://errors.angularjs.org/1.3.7/ngModel/nonassign?
profile-edit.html
<input id="birthday" type="date" class="form-control" ng-model="account.birthday | date" datepicker-options="dateOptions" close-text="Close" />
Backend Account Entity:
#Entity
#Table(name = "account")
#JsonIgnoreProperties(ignoreUnknown = true)
public class Account extends BaseEntity implements Serializable {
....
#Column(name = "BIRTHDAY")
private Date birthday;
}
The account.birthday field in debugger seems to hold milliseconds in plain string after the account was fetched from backend.
Right from the debugger:
active: true
birthday: 241912800000
city: "Essen"
country: "Germany"
created: 1450289294000
How do I fix this?

I have used <input type="date" data-ng-model="from_date"> as HTML code and then parsed it in date in Angular as
var var_name = new Date($scope.from_date);

Related

Angular Js how to get checkbox value on edit and submit?

<input type="checkbox" ng-model="mail.email" name="email"
ng-true-value="'mail.email'" ng-false-value="'0'">
This is my code while im going to edit i need to fetch the value from database but if i click the checkbox it shows the following response
{
regid: "NADr333434",
email: "mail.email",
altemail: "mail.altemail",
htmlcontent: "<b>kuhiuhioh oih oihih</b>"
}
I need the output as the follwing format how to get this
{
regid: "NADr333434",
email: "test#gmail.com",
altemail: "alternate#test.com",
htmlcontent: "<b>kuhiuhioh oih oihih</b>"
}

NgFor only supports binding to Iterables such as Arrays while using array to create a dropdown selection

I am getting the below error while running the application:
ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'subLandscape'. NgFor only supports binding to Iterables such as Arrays.
The subLandscape variable I am referring to in the HTML is an array but it throws an error while using it with "ngFor"
HTML:
<div class="form-group" [class.has-error]="subLandscape.invalid && subLandscape.touched">
<strong>Sub Landscape</strong>
<br>
<p>Please choose from one of the Sub Landscape options. Sub Landscape options are for reporting only.</p>
<label class="control-label">SubLandscape:</label>
<mat-select #subLandscape="ngModel" type="text" class="form-control" name="subLandscape" [ngModel]="model.subLandscape">
<mat-option *ngFor="let item of subLandscape">
{{ item }}
</mat-option>
</mat-select>
<div *ngIf="subLandscape.invalid && subLandscape.touched" class="alert alert-danger">
Select the Sub Landscape from the provided list.
</div>
</div>
Model:
export class SModel {
constructor (
public description: string,
public reasons: string,
public projectName: string,
public subLandscape: string,
public centerdata: string,
public nom: number,
public size: string,
public dbgh: string
) {
}
}
Component:
import { Component, OnInit } from '#angular/core';
import { Standalone } from '../standalone';
import { StandaloneModel } from '../models/standalone.model';
import {MatTableModule, MatTableDataSource} from '#angular/material/table';
#Component({
selector: 'app-standalone-form',
templateUrl: './standalone-form.component.html',
styleUrls: ['./standalone-form.component.css']
})
export class StandaloneFormComponent {
public project: string[] = ['', 'appdev', 'apptest', 'appqa'];
public subLandscape: string[] = ['DEV', 'Testing', 'QA', 'UAT'];
public dataCenter: string[] = ['PDC', 'SDC'];
public model = new SModel('', '', '', '', '', 0, '', '');
}
Probably because it is unable to differentiate between subLandscape from
#subLandscape="ngModel" and the component property array public subLandscape: string[] = ['DEV', 'Testing', 'QA', 'UAT'];. Change the name of either should solve the problem

can,t able to save hindi unicode character into mongodb for multiple fields

can,t able to save hindi unicode character into mongodb for multiple fields
const WordsSchema = mongoose.Schema({
word1:{
type: String,
required: true,
language_override:"Hindi"
},
word2:{
type: String,
required: true,
language_override:"Hindi"
}
});
on setting language_override i able to save word1 but it don,t save word2
Code on angular side is ->
<input class="form-control keyboardInput" id="Hindimeaning" [(ngModel)] ="word1" name="word1" placeholder="Meaning in Hindi 1" type="text">
<input class="form-control keyboardInput" id="Hindimeaning2" [(ngModel)] ="word2" name="word2" placeholder="Meaning in Hindi 2" type="text">
how can i save value for both inputs ....

Angular Typeahead: Convert value to number on the fly

Assuming I have the following data which i get from the server using
$scope.users= UserResource.query();
//$scope.users= [{id: "1", name: "John"}, {id:"2", name: "Tom"}]
Is it possible to make typeahead bind to the NUMBER id instead of the STRING id?
For example, I want $scope.person.id to be 1 instead of "1" so I don't get any complaint from the angular when I select a value. Right now, because id is of type string, my number field gets this error: Error: [ngModel:numfmt] Expected 1 to be a number
Something like this:
<input ng-model="person.id class="form-control" type="number" typeahead="parseInt(user.id) as user.name for user in users | filter:$viewValue" />
The above doesn't work, and so does the following:
<input ng-model="person.id class="form-control" type="number" typeahead="user.id as user.name for user in users | filter: number | filter:$viewValue" />
P.S. Of course I don't need any client side validation for the id field. This is just a quick 30 secs example to illustrate the issue.
You can write your own filter for this and use it:
user.id as user.name for user in (users | stringToId:'user.id')

Binding date value to ng-model in angular kendo date picker

I have an api which return the date in this format "014-08-26T15:10:45.402Z" i am using angular kendo ui .The problem i am facing is the date is not getting bound to the kendo date picker.Could someone help me out .
<input kendo-date-picker ng-model="emp.datestart" k-format="MM/dd/yyyy" />
In order to have the Kendo DatePicker working with a string date value model you need:
1) Use k-ng-model instead of ng-model.
2) Tell the widget in which exact format the date will be parsed.
<input kendo-date-picker k-ng-model="emp.datestart" k-options="datePickerOptions" />
Then at your AngularJS controller you will specify the date parsing format, for example:
$scope.datePickerOptions = {
parseFormats: ["yyyy-MM-ddTHH:mm:ss"]
};
you can use something like this
<h4>Select date:</h4>
<input
kendo-date-time-picker
k-options="monthSelectorOptions"
data-k-ng-model="dateObject"
data-ng-model="dateString.startDate"
style="width: 100%;" />
var startDate = new Date();
$scope.monthSelectorOptions = {
value: startDate,
format: "dd/MM/yyyy h:mm tt",
parseFormats: ['ddd MMM dd yyyy'],
animation: {
close: {
effects: "fadeOut zoom:out",
duration: 300
},
open: {
effects: "fadeIn zoom:in",
duration: 300
}
},
culture: "de-DE",
};
And here is complete solution on kendo dojo

Resources