Pass Constant Values to Angular from _layout.cshtml

前端 未结 3 479
无人及你
无人及你 2021-01-05 17:52

Okay, so I have a constant variables in the _Layout.cshtml of ASP.Net SPA project and I would to pass them so that Angular will have access to those.

How can I do t

3条回答
  •  轮回少年
    2021-01-05 18:36

    What is the problem? I have easily get value from an HTML page like this.

    HTML

    
      
        
        Angular 2 - Tour of Heroes
        
        
        
    
        
         
        
    
        
        
        
    
        
        
            
    
        
      
      
      
        Loading...
      
    
    

    Call Main Component file

    alert(getThisValue);

        import { bootstrap } from '@angular/platform-browser-dynamic';
        import { HTTP_PROVIDERS } from '@angular/http';
        import { AppComponent } from './app.component';
        //import { enableProdMode } from '@angular/core';
    
        //enableProdMode();
    
        bootstrap(AppComponent, [HTTP_PROVIDERS]);
    
        alert(getThisValue);
    

    It's work for me

    On thing I have notice in your code is you should use '' mark to access url.

    Replace this

    var lenderValues = @Html.Action("GetLenderDropdownValues", "Dropdown");
    

    with this

    var lenderValues = '@Html.Action("GetLenderDropdownValues", "Dropdown")';
    

    This is the simplest option to access value from HTML of course not a proper way. To access this value you need to define a constant as defined in Thierry Templier answer above.

提交回复
热议问题