2

I want to pass a value from my C#/Razor to angularJS.

I tried this:

{{isDashboardOpened=@((ViewContext.Controller.GetUserSettings(this.User).ShowDashboardOnLoad).ToString().ToLower());""}}

It didnt work well, because after this I can't change my variable any more.

Here is the rest of my code:

 <li id="btnDashboard" ng-click="toggleDashboard()" ng-class="{'active':isDashboardOpened}">
                        <a href="#" onclick="return false;">
                            <span class="glyphicon glyphicon-dashboard" title="@ResourcesLocal.Widgets.Resources_WidgetBase.Dashboard"></span>
                        </a>
                    </li>


angular.module("frigodataOnline")
.controller("ProjectViewController", ["$scope", function ($scope) {
    $scope.isDashboardOpened = false;

    $scope.toggleDashboard = function () {
        $scope.isDashboardOpened = !$scope.isDashboardOpened;
    };

    $scope.openDashboard = function () {
        $scope.isDashboardOpened = true;
    };

    $scope.closeDashboard = function () {
        $scope.isDashboardOpened = false;
    };
}]);

When I havent implement my frst line (razor to ang) then my toggle work, if I implement it, the toggle doesnt work any more.

1 Answer 1

1

You can use ng-init

<li id="btnDashboard" ng-click="toggleDashboard()" ng-init="isDashboardOpened='@((ViewContext.Controller.GetUserSettings(this.User).ShowDashboardOnLoad).ToString().ToLower());' ng-class="{'active':isDashboardOpened}">
                    <a href="#" onclick="return false;">
                        <span class="glyphicon glyphicon-dashboard" title="@ResourcesLocal.Widgets.Resources_WidgetBase.Dashboard"></span>
                    </a>
                </li>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.