2013-09-26 61 views
0

我有一個AngularJS控制器,我想在我的MVC webform查看頁面中使用。如何在webform中實現AngularJS控制器?

我創建了一個簡單的代碼,但似乎沒有工作。

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> 

我期待看到這個詞測試,但它不綁定。我只看到

回答

0

您需要模塊中的第二個參數,即在當前模塊之前加載注入器的模塊數組。在這種情況下,它將是空的。

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

您還沒有參考加載angular.js腳本的頭部

+0

我在其他的js引用的angular.js。我試圖把[],但我的頁面沒有完成從加載 – chary

+0

我也試過把ng-app的標記,仍然無法正常工作。我錯過了什麼嗎? – chary

+0

我在http://plnkr.co/edit/rC5yVV?p=preview上創建了一個Plunk – user2789093