Krohn Krohn - 9 days ago 5
AngularJS Question

$scope variables not loading on mvc view, no errors displayed either

I am trying to set up an angular-approached MVC site to show my new boss some benefits of using it - with irony that I got stuck now.

The issue is that interpolating variables onto my view does nothing - it remains clear. I'm running in an MVC 4 environment, and sofar, just binding a

ng-model
on a textbox worked, but getting a value from a controller on-load doesn't

the javascript:

var UpdateCataloguesController = function ($scope) {
$scope.message = "Hello Wurld!";
}

UpdateCataloguesController.$inject = ["$scope"];

asdf.controller('updateCatalogues', UpdateCataloguesController);


The html (the
<body>
tag has
ng-app="asdf"
on it, so omitting it here)

<input type="text" ng-model="helloAngular" ng-strict-di />
<h1>{{helloAngular}} -- THIS WORKS</h1>


<p ng-controller="updateCatalogues">
<div>{{message}} -- NOTHING BOUND HERE~</div>
</p>


Why isn't
{{message}}
interpolating onto my page?

Answer

You are putting a block element inside an inline element which doesn't work.

Try this:

<div ng-controller="updateCatalogues">
    <p>{{message}} -- NOTHING BOUND HERE~</p>
</div>
Comments