Create a service called InitialData. It will return data that you set in 
razor view. In this way you will have initial data ready for Angular to 
process once your view has loaded.
See 
this: 
https://github.com/dlidstrom/Tasks/blob/master/Tasks/Views/Home/Index.cshtml
And 
this: 
https://github.com/dlidstrom/Tasks/blob/master/Tasks/Content/app/initialdata.js

Demo online: http://tasksdemo.azurewebsites.net

Hope this helps!

On Tuesday, March 11, 2014 3:41:14 PM UTC+1, Denis Ipatov wrote:
>
> How can I initialize a variable in controller from a view (for example 
> fetching in from ASP.NET model)? Something like below:
>
> var app = angular.module("app", []);
> app.controller("appCtrl", function ($scope) {
>      $scope.myvar;
>
> and in html file:
>
> <div ng-app="app" ng-controller="appCtrl">
>   {{myvar = 5}}
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to