0

I have a controller with

$scope.Id = 'something';

In html

<div ng-include="~[some path]/something.cshtml'" ng-controller="ChildController" id="#{{Id}}" ng-init="Id = Id"></div>

In generate HTML, id="#something" is correctly generated.

But in childcontroller, $scope.Id is 'undefined'.

It looks lik ChildController is initiated before its "parent" conroller. What can I do about this?

TTT
  • 1,848
  • 2
  • 30
  • 60

1 Answers1

0

The problem is because ng-controller & ng-include both does create a new scope which is prototypically inherited from parent.

Use dot rule while dealing with scope hierarchy/inheritance.

$scope.data = {Id :'something' }

On html you need to use it like

{{data.Id}}

Demo Here

Edit

You could not load .cshtml file form its path you should have to load it from the ASP.NET MVC controller's action because it can have C# content that needs to parse through C# view engine before rendering it on view.

Community
  • 1
  • 1
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299