理解angularjs中的路由和模板html,简单的例子是可能的
understanding routes and templates html in angularjs, simples example possible
我正在尝试将angularjs嵌入到我现有的asp.net mvc4应用程序中。
(视图/共享/)_Layout.cshtml
<html data-ng-app="myApp">
<head>
<script src="~/Scripts/angular.min.js"></script>
<script src="/js/main.js"></script>
</head>
<body>
@RenderBody()
</body>
</html>
/js/main.js
var app = angular.module("myApp", []);
module.config(function ($routeProvider) {
$routeProvider.when("/topics", {
controller: "topicsController",
templateUrl: "/js/templates/topicsView.html"
});
$routeProvider.otherwise({ redirectTo: "/" });
});
app.controller("topicsController", function ($scope) {
$scope.testData = "some dummy data";
});
/js/templates/topicsView.html
<h1>topics template view, dummy object </h1>
{{ testData }}
以及/Views/Home/Index.cshtml内部
<div data-ng-view=""></div>
我试图使用#/topicsurl导航到/topics,但没有任何内容(空白页,而不是404),甚至templates/topicsView.html
中的h1标题也没有
我做错了什么?
您忘记包含ngRoute
模块。试试这个:
var app = angular.module("myApp", ['ngRoute']);
创建angular主应用程序模块时,需要将angular-routes.js和angular.js一起包含,然后将ngRoutes模块作为依赖项包含在内。
相关文章:
- AngularJS-简单的教程不起作用
- AngularJS控制器不工作,为什么?(简单的控制器示例)
- 如何在angularjs中进行简单的菜单导航
- 为什么我在简单的 AngularJS 程序中收到此错误
- angularjs做一个简单的倒计时
- 简单顺序通过过滤器在 AngularJs 中不起作用
- 简单的AngularJS控制器不起作用
- Angularjs 错误中的简单选项卡系统
- 为什么AngularJS在页面加载时没有自动绑定属性?包括一个非常简单的例子
- 在Angularjs服务中为返回对象引用的http请求提供的数据构建简单的缓存
- AngularJS中的简单数据库搜索引擎
- Angularjs - 简单的表单提交
- AngularJs 简单的自定义服务不起作用
- Angularjs 简单网格 表按日期排序
- 如何在 angularjs 中的简单获取请求 json 之后添加事件侦听器
- AngularJS $http.post ASP.NET 具有简单类型参数的 Web API 控制器
- 使用 Lodash 或 AngularJS 测试对象中是否存在值的最简单方法是什么?
- AngularJS简单控制器不起作用
- AngularJS:判断没有(各种类型的)输入是否为真的最简单方法
- 如何在AngularJs中进行简单的哈希标记(hash tag)路由