【问题标题】:How to implement an AngularJS controller in a webform?如何在 Web 表单中实现 AngularJS 控制器?
【发布时间】:2013-09-26 04:29:07
【问题描述】:

我有一个 AngularJS 控制器,我想在我的 MVC 网络表单视图页面中使用它。

我创建了一个简单的代码,但似乎不起作用。

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>

我希望看到 test 这个词,但它没有绑定。我只看到 {{text}}

【问题讨论】:

    标签: angularjs webforms viewpage


    【解决方案1】:

    你需要在模块中的第二个参数,一个模块数组,供注入器在当前模块之前加载。在这种情况下,它将是空的。

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

    您也没有参考在头部加载 angular.js 脚本

    【讨论】:

    • 我已经在我的其他 js 中引用了 angular.js。我尝试放置 [] 但我的页面没有完成加载
    • 我也试过把 ng-app 放在 标签里,还是不行。我错过了什么吗?
    猜你喜欢
    • 1970-01-01
    • 2013-10-09
    • 1970-01-01
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    • 2020-02-04
    • 2017-10-23
    • 1970-01-01
    相关资源
    最近更新 更多