Learning AngularJS and use it with ASP.Net MVC – Controller on MVC view

I’ve been using book Build Single Page Application with ASP.Net MVC 5 and AngularJS.

On chapter 4, at Creating first angular controller, book’s code didn’t work in my case. I’m using Angular version 1.3.15.

I had to make following changes:

At _Layout.cshtml, identify the app:

<html ng-app=”myApp”>

At homeIndex.js (the file storing the angular controller definition):

//homeIndex.js

var app = angular.module(myApp, []);

app.controller(‘homeIndexController’, function ($scope) {

$scope.fname = “John”;

$scope.lname = “Doe”;

});

 

And at the view, from where the angular controller is supposed to be called, Index.cshtml:

@section scripts

{

<script src=”~/js/homeIndex.js”></script>

}

<div ng-app=”myApp” ng-controller=”homeIndexController”>

Fname:- {{fname}} <br />

Lname:- {{lname}}

</div>

Will write this comment at Amazon too. Either AngularJS has changed since the version author was using (he says it is 1.2.26 or there may be some errors on sample code at the book.

Cheers.

Leave a Reply

Your email address will not be published. Required fields are marked *