logo
down
shadow

Calling ts. function from HTML to change its parameters


Calling ts. function from HTML to change its parameters

Content Index :

Calling ts. function from HTML to change its parameters
Tag : angular , By : mansoor
Date : January 12 2021, 07:00 PM

this will help I have a ts. function in my component.ts for reading data out of JSON file. This take a number as a parameter which is responsible for specifying the data read of the JSON file. I want to "control" this parameter from HTML (component.html). What I really want is to use a select tag and by choosing one I call that ts. function. (e.g. I have 3 options in that select tag and each of them call the function but with different parameter) , You can do it like that in your .ts file
myFunction(param: number) {
// fetch your data or whatever you want to do;
fetchData(param) 
}
<select (change)="myFunction($event.target.value)">
    <option *ngFor="let i of options">{{i}}</option>
</select>

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

HTML select tag value does not immediately change after calling a function from script


Tag : javascript , By : jazzyfox
Date : March 29 2020, 07:55 AM
Does that help you have to save the current select state during the function. Here is a small adaption (see commented lines)
<script language="javascript" type="text/javascript">
    function createNewSelectTag()
    {
        /*check if 2nd select tag is already exist. if it is, cannot make another 2nd select tag*/
        if (document.getElementById('createdSelectTag'))
            {
            if (document.getElementById('SelectTag1').selectedIndex == 0)
                {
                    var element = document.getElementById('createdSelectTag');
                    element.parentNode.removeChild(element);
                }
            }
            else
            {
                // save selected state
                var holdState = document.getElementById('SelectTag1').selectedIndex;
                if (holdState > 0)
                {
                           var newSelectTag = '<li id="createdSelectTag"><span>2nd Select Tag   :</span>' +
                                                '<select id="SelectTag2">' +
                                                     '<option value="a">A</option>' +
                                                     '<option value="b">B</option>' +
                                                     '<option value="c">C</option>' +
                                                 '</select>' +
                                             '</li>';
                           document.getElementById('MAIN').innerHTML += newSelectTag;
                           // set to saved state
                           document.getElementById('SelectTag1').selectedIndex = holdState;
                }
            }
    }
</script>

How to change a variable when calling a function with parameters in javascript?


Tag : javascript , By : Bimal Poudel
Date : March 29 2020, 07:55 AM
hop of those help? I have a function in my javascript file: , when you do this:
element.on('mouseenter', hoverWidgetOn('background-color', 'red')) 
element.on('mouseenter', function() { 
    hoverWidgetOn.call(this, 'background-color', 'red') 
}); 

Calling a function on a HTML check box change without submission using C#


Tag : chash , By : can
Date : March 29 2020, 07:55 AM
hope this fix your issue You can do this with C# in code behind. Add a OnCheckedChanged event to the CheckBox and set the AutoPostBack to true and handle the change. Note that a Panel becomes a div in HTML.
<asp:CheckBox ID="limitOptions" runat="server" OnCheckedChanged="limitOptions_CheckedChanged" AutoPostBack="true" />

<asp:Panel ID="locationOptions" runat="server" Visible="false">
    Radius (KM) <asp:TextBox ID="radius" runat="server" Text="100"></asp:TextBox>
</asp:Panel>
<asp:CheckBox ID="limitOptions" runat="server" onclick="toggleOptions()" />

<div id="locationOptions" runat="server" style="display: none">
    Radius (KM)<asp:TextBox ID="radius" runat="server" Text="100"></asp:TextBox>
</div>

<script type="text/javascript">
    function toggleOptions() {
        var id = '#<% =locationOptions.ClientID %>';
        if ($(id).css('display') == 'none') {
            $(id).slideDown('fast', function () { });
        } else {
            $(id).slideUp('fast', function () { });
        }
    }
</script>

python function calling with dict - calling a function which has parameters but not listing the parameter explicitly


Tag : python , By : Elwillow
Date : March 29 2020, 07:55 AM
this one helps. You are partially correct, you need to pass a parameter. Look at this line
items = sorted(word_count.items(), key=get_count, reverse=True)
items = sorted(word_count.items(), key=lambda x: -x[1])

Calling javascript Function from HTML with multiple parameters


Tag : javascript , By : christiandsg
Date : September 25 2020, 12:00 PM
Any of those help I'm trying to call a javascript function called confirmRemove(title, id) to remove an element from a table. This function should be called when the user clicks on a link that looks like an "X". I attached my code below to show how I went about doing this, but I'm seeming to be having some errors and I'm not sure why. Most of the elements are able to be removed, but for a few when I click the link to call the function, nothing happens. Is there a better way of doing this? Not sure why this would happen. , You can try this code
<td> <a onclick="confirmRemove('<?php echo $title; ?>','<?php echo $id; ?>')" 
   href="javascript:void(0)">X</a></td>
Related Posts Related QUESTIONS :
  • Want only single true or false value from observers
  • How to add react custom element in angular 6
  • StaticInjectorError(AppModule)[MainComponent -> MatDialog]
  • Loop through data set showing undefined
  • Why does the Angular Material table mat-paginator pagesize not work?
  • Can Web API get input from angular client for confirmation and continue execution?
  • Will the angular build include the spec file size?
  • Meta tags angular 7
  • Can't find file on stackblitz Angular project
  • AngularFire Auth exchange FireBase token for my platform's token before re-direct
  • Angular 8 Component / Service: How to retrieve data from async function in service
  • Add a control to a dynamic Angular reactive form
  • Looking to Add Role-Based Authentication System
  • Angular 7/8, 1 dependency is interfering with another one, How to avoid the loading of a deep dependency while inside a
  • Compiler errors (resolving) when compiling after addition of Firebase Admin SDK
  • wrapper observable event on top of http call
  • Nginx container does not send requests to back-end
  • ngOnInit starts before APP_INITIALIZER is done
  • How to trigger a data service call in Angular
  • Where do I declare my external service in my app.module.ts file?
  • event propagation cdk drag
  • use argument as object property in angular
  • How to create new object in redux selector and return it
  • How can I show my own text status before i switch my toggle button while using mat-slide-toggle
  • Get the API response and store the data in to an array
  • How to obtain previous and new value from Angular mat-select?
  • Send payload data with POST/PUT/PATCH requests to Sentry.io
  • Angular 8 not working in IE 11 and Safari browser
  • How to create function name from json in Angular 7
  • Im trying to push values from an array with objects to another array with objects
  • Got an error when I add "changeDetectionStrategy" to my app
  • Angular typescript object undefined at start leading to undefined error
  • Failed: Template parse errors: There is no directive with "exportAs" set to "bsDatepicker" while run
  • Error: Can't resolve all parameters for setupPlatform: (?, [object Object], [object Object])
  • Differences between ng build and ng build --watch
  • Does an angular component ever destroy when it is subscribed to router change event once?
  • How do I get the JSON response from httpModule.get?
  • Ngx-logger implementation in angular 8
  • font size increase decrease by button using angular 7
  • Are selectors and module declarations mandatory for components?
  • Why angular is adding '#' in each route?
  • how to block the subsequent clicks in angular?
  • Ionic Angular TypeError: architect_1.createBuilder is not a function
  • Angular app doesn't work on Firefox after updating it to Version 8
  • Angular: Formatting numbers percentage
  • Matrix in FormGroup [Angular 2+]
  • "export 'DOCUMENT' was not found in '@angular/platform-browser'
  • angular autocomplete material
  • Prevent click event from triggering other click elements undernethe the front element
  • How to know when an image has been fully loaded in angular?
  • How to read config file to set API URL inside an Angular App packaged as a WAR and deployed on IBM Liberty
  • npm ERR! Unexpected end of JSON input while parsing near
  • override custom scss variable inside another angular-cli(7) (library) project
  • Angular-7 How to navigate to certain section of the single page website
  • how to disable an input field from a group of input fields in Angular
  • How to unit test selection of a mat-autocomplete option?
  • angular 8 form reset with value not working correctly
  • ng: error in production with Cb(...).firestore is not a function
  • Property 'result' does not exist on type 'EventTarget'
  • Cannot read property 'subscribe' of undefined on Ionic 4 , Angular 8
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com