我在我的代码中搜索了很多问题,但没有得到解决方案。我正在尝试在 html 文件中路由有两个链接 1 用于视图 1 和第二个用于视图 2 两个视图的代码位于名为部分的文件夹中的不同文件中,在 js 文件中我已经创建了一个名为 mymodule " 从 html 文件中的 an-app 然后 {{studname }} 工作正常,但在添加 "mymodule" 后我收到错误
html文件代码:
<!DOCTYPE html>
<html ng-app="mymodule">
<head>
<title>Try Deep linking</title>
<script src="angular.min.js"></script>
<script type="text/javascript" src="route.min.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</head>
<body>
<input type="text" name="" ng-model="studname" />
<p>{{ studname }}</p>
<div ng-view>
</div>
<a href="#/view1">View 1</a>
<a href="#/view2">View 2</a>
</body>
</html>
JS代码:
var myapp = angular.module("mymodule",[]);
myapp.controller( "mycontroller", function ($scope) {
$scope.student = [
{name : "Abhay Sehgal", city: "Delhi" },
{name : "Pankaj Singh", city: "Bihar" },
{name : "ujjwal", city : "UP"}
];
});
myapp.config(function($routeProvider){
$routeProvider
.when('/view1',{
controller : "mycontroller",
templateUrl : "parts/view1.html"
})
.when('/view2',{
controller : "mycontroller",
templateUrl : "parts/view2.html"
})
.otherwise({redirectTo :'/'});
});
提前致谢
您需要将依赖项添加ngRoute
到您的模块中,
var myapp = angular.module("mymodule",['ngRoute']);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句