0

I have an AngularJS controller that I want to use in my MVC webform view page.

I have created a simple code but does not seem to work.

Test.js

angular.module('project').controller("TestCtrl", function($scope){
  $scope.text = 'test';
});

View.aspx

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<SampleProject.Models.ReportInfo>" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" ng-app="project">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server" ng-controller="TestCtrl">
        {{text}}
    </form>
</body>
</html>

I'm expecting to see the word test, but it does not bind. I only see {{text}}

chary
  • 57
  • 13

1 Answers1

0

You need a second parameter in module, an array of modules for the injector to load before the current module. In this case it will be empty.

angular.module('project', []).controller(....

You also have no reference to load angular.js script in the head

user2789093
  • 371
  • 3
  • 12
  • I have referenced the angular.js in my other js. I tried putting the [] but my page did not finish from loading – chary Sep 26 '13 at 06:16
  • I also tried putting the ng-app in tag, still does not work. Am I missing something? – chary Sep 26 '13 at 07:13