Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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}}

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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

share|improve this answer
 
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 6:16
 
I also tried putting the ng-app in <body> tag, still does not work. Am I missing something? –  chary Sep 26 '13 at 7:13
 
I have created a Plunk at plnkr.co/edit/rC5yVV?p=preview –  user2789093 Sep 26 '13 at 9:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.