How to add attributes to ngform object in component class - angularjs

My form object is JSON.Stringify(form.value) looking like this
"body":{
"panNo":"IRFPP1993A",
"ackNo":"123456789"
}
I want output like this (I want to hardcord one new value inside
"body":{
"requestType":"getStatus",
*panNo":"IRFPP1993A",
"ackNo":"123456789"
}
Please help me ...! Thanks in advance..!

You can add this code in controller
if(form.value){
form.value.requestType = 'getStatus';
}

Related

Can't access array's elements in child component in Angular

Problem is:
I have an array called wycieczki in parent.component.ts where I can easily (for example) do something like console.log(this.wycieczki[0]);
but when I pass it to child.component.ts, trying to do the same will result in undefined
Additionally, console.log(wycieczki) works in child.component.ts
Binding code (in case I am missing something, but I did check it with regular variable and it worked):
parent.component.html
<app-child [(wycieczki)]="wycieczki" ></app-child>
child.component.ts
`
#Input() wycieczki: Wycieczka[] = [];
#Output() wycieczkiChange = new EventEmitter<Wycieczka[]>();
constructor() { }
ngOnInit(): void {
console.log(this.wycieczki)
console.log(this.wycieczki[0])
}
`
Original idea was to have the child component filter the wycieczki array, and then problems appeared.
Will probably look in comments when I get up tomorrow. Thanks for any help in advance
Simply change
<app-child [(wycieczki)]="wycieczki" ></app-child>
to
<app-child [wycieczki]="wycieczki" ></app-child>
It should work.
() is used for two-way data binding i.e #output of child.

ngx Datatable update header dynamically

I am using the component ngx-datatable in my angular app and I am trying to update the header texts dynamically.
What I was trying was the following:
<ngx-datatable-column prop="day_1" name="{{day_1_header}}">
and updating the day_1_header property dynamically, but when I do so the change is never reflected.
I have also tried adding a ViewChild and changing the name directly like so:
HTML:
<ngx-datatable-column #dataTable1 prop="day_1" name="{{day_1_header}}">
TS:
#ViewChild('dataTable1') dataTable1;
[..]
this.dataTable1.nativeElement.name = "test";
When I check the properties of my dataTable1 object the new name is set.
So can anyone tell me how to rerender/sync the datatable headers?
Thanks!
Damn...
Tried forever, asked the question and found a solution right away.
It worked by adding an explicit header-template to the column like this:
<ngx-datatable-column>
<ng-template let-column="column" ngx-datatable-header-template>
{{day_1_header}}
</ng-template>
</ngx-datatable-column>
Maybe it helps someone someday.
I have no idea why the other answer (which seems pretty direct and logical) didn't work for me. Maybe breaking change in higher version.
This GitHub issue gives another perspective on how to achieve it.
There's also this example in the source code that shows it.
Basically, you'll need the custom template for the column header
<ngx-datatable
class="material"
[rows]="rows"
[columns]="columns"
[columnMode]="ColumnMode.force"
[headerHeight]="50"
[footerHeight]="50"
rowHeight="auto"
>
</ngx-datatable>
<!-- custom column header template -->
<ng-template #hdrTpl let-column="column"> <strong>Fancy</strong>: {{ column.name }} !! </ng-template>
Then access it in your component class with #ViewChild() decorated property.
export class TemplateRefTemplatesComponent {
#ViewChild('hdrTpl', { static: true }) hdrTpl: TemplateRef<any>;
rows = [];
columns = [];
ColumnMode = ColumnMode;
constructor() {
}
ngOnInit() {
// You'll need to map over all columns to use it in all
this.columns = this.columns.map(columns => ({...columns, headerTemplate: this.hdrTpl});
}
}

Undefined Values in Kendo Dropdownlist

I am using Telerik's dropdownlist in my MVC application View. I am facing two problems:
1) When I run my application, I find every value of kendo dropdownlist is "Undefined".
This is the code for my View:
#model IEnumerable<EulenMgrKendoUIMvcApplication.Dominio.Tablas.DelegacionProductoUsuario>
#(Html.Kendo().DropDownListFor(d=>d)
.Name("IdDelegacionProductoDrpDwn").HtmlAttributes(new { #style = "font-size:12px" })
.DataTextField("IdDelegacionProducto")
.DataValueField("IdDelegacionProducto")
**.BindTo((System.Collections.IEnumerable)ViewData["IdDelegacionProducto"]))**
This is my controller, where I populate the dropdownlist:
public class DelegacionProductoUsuarioController : Controller
public ViewResult List()
{
IEnumerable<DelegacionProductoUsuario> delegaciones = DelegacionProductoUsuario.GetAll();
**PopulateDelegacionProducto();**
return View(delegaciones);
}
private void PopulateDelegacionProducto()
{
List<Int64> IdDelegacionProductoList = new List<Int64>();
foreach( DelegacionProductoUsuario d in DelegacionProductoUsuario.GetAll()){
IdDelegacionProductoList.Add(d.IdDelegacionProducto);
}
ViewData["IdDelegacionProducto"] =IdDelegacionProductoList ;
}
}
>I am debugging the application and the controller is passing to the view the proper values,so I don't understand why it doesn't show them.
2) Second problem: I insert this Dropdownlist in one of the columns of a kendo grid with no success.
In it's place it appears a common label. Here is the code for my Grid, I mark in Bold the column where I try to show my dropdownList:
#(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns=>
{
columns.Bound(d => d.BorradoLogico).Title("Borrado logico");
columns.Bound(d => d.FTick).Title("Ftick");
**columns.Bound(d => d.IdDelegacionProducto).Title("IdDelegacionProducto").EditorTemplateName("IdDelegacionProductoDrpDwn");**
columns.Bound(d => d.IdUsuario).Title("IdUsuario");
})
How does that 'DelegacionProductoUsuario' class look like? Does it have property named 'IdDelegacionProducto' ? It looks like you have not set the dataValueField correctly.
As for the second question, where did you put that EditorTemplate (is it in the Shared/EditorTemplate or in a EditorTemplates folder? More info about editor template can be found here.
Dear Petur: thanks a lot for answering. On regard to your answer:
My class DelegacionProductoUsuario does have a property called IdDelegacionProducto. On regard to your question "where I place the EditorTemplate" , I don't understand what you mean, I place it in the view that Lists all of my DelegacionProductoUsuario . Please keep on helping me. Thanks a lot Petur.

cakephp The eventKey variable is required

I'm getting the following error message on all my pages in cakePHP:
The eventKey variable is required
Does anyone know what this is and how to get this fixed?
I have no clue where it comes from.
Thanks!
Please check for an empty Construct { } in your models
It can be naming function too.
When function name is similar/like model name, my example:
model ProfileFriend,
function: function profileFriend(){...}
use: $this->ProfileFriend->profileFriend();
Yeah I know, my function name looks weird when I write model name before function name, but when my code look like this:
$model = $this->modelClass;
// ....
$is_friend = $this->$model->profileFriend();
// ...
... then my function name doesn't looks so weird.

CakePHP - Changing default Flash layout

I know that I can replace the flash markup by creating something like custom_flash.ctp in Elements folder and call it like:
$this->Session->setFlash('Hello', custom_flash)
But how can I use custom layout when not adding the second parameter?
$this->Session->setFlash('Hello')
I thought I can replace the default by having a file named default.ctp inside Elements folder. But I can't.
I want to keep the code as short as possible. That's why I'm looking a way to do this
Any solution? Thanks
Try to create your Component:
class MySessionComponent extends Session {
public function setFlash($message) {
return $this->setFlash($message, 'custom_flash');
}
}
and than in your controller just use:
public $components = array('MySession');
$this->MySession->setFlash('Hello');
I found the answer from this question.
We need to add this codes in app/Controller/AppController.php
function beforeRender(){
if ($this->Session->check('Message.flash')) {
$flash = $this->Session->read('Message.flash');
if ($flash['element'] == 'default') {
$flash['element'] = 'fileNameOfYourCustomFlash';
$this->Session->write('Message.flash', $flash);
}
}
}
It basically add element parameter in flash when it doesn't exist yet.
This is explained on the cakephp website here

Resources