AngularJS without SPA and using ASP.NET MVC routing

前端 未结 1 1486
渐次进展
渐次进展 2021-02-11 09:25

I want to use AngularJS non-SPA for my website along with ASP.NET MVC. The authentication happens through Active Directory so I find it best to use ASP.NET MVC for routing and a

相关标签:
1条回答
  • 2021-02-11 10:00

    Updated Answer:

    Since you are not using Angularjs routing, you can use ngInit. It will initialize a new variable in your controller's scope and you will be able to access it like:

    HTML (inside your controller):

    <AnyElement ng-init="roomID = @ViewBag.roomID"></AnyElement>
    

    JavaScript:

    var roomID = $scope.roomID;
    

    For more explanations see ngInit documentation.

    Original Answer:

    In Angularjs you can access the query string parameter very easily like:

    var paramValue = $routeParams.yourParameterName;
    

    Or if you want to initialize a JavaScript variable then consider using ngInit. It will initialize a new variable in your controller's scope and you will be able to access it like:

    HTML (inside your controller):

    <AnyElement ng-init="roomID = @ViewBag.roomID"></AnyElement>
    

    JavaScript:

    var roomID = $scope.roomID;
    

    For more explanations see ngInit documentation.

    Hope that helps.

    0 讨论(0)
提交回复
热议问题