Angular JS UI示例应用程序不工作
问题描述:
我试过UI路由器示例应用程序(plnkr.co/edit/u18KQc?p=preview),但是当我在浏览器中运行相同的代码时,它不起作用。 API的最近更改?直到“$ urlRouterProvider.otherwise(”/ route1“)”它正在工作,因为它最初路由到“/ route1”。Angular JS UI示例应用程序不工作
附加文件将以index.html(在同一目录中):
- route1.html
- route1.list.html
- route2.html
-
路径2。 list.html
var myapp = angular.module('myapp', ["ui.router"]) myapp.config(function($stateProvider, $urlRouterProvider){ // For any unmatched url, send to /route1 $urlRouterProvider.otherwise("/route1") $stateProvider .state('route1', { url: "/route1", templateUrl: "route1.html" }) .state('route1.list', { url: "/list", templateUrl: "route1.list.html", controller: function($scope){ $scope.items = ["A", "List", "Of", "Items"]; } }) .state('route2', { url: "/route2", templateUrl: "route2.html" }) .state('route2.list', { url: "/list", templateUrl: "route2.list.html", controller: function($scope){ $scope.things = ["A", "Set", "Of", "Things"]; } }) })
答
AngularJS通过AJAX调用和电话等负载模板可以当它运行从服务器页面,从文件系统加载您的应用程序(在地址栏file:///
)将无法正常工作只能由浏览器发出的。
您可以使用一个简单的服务器,例如python -m http.server
意味着需要做什么改变? – user2216267
只需打开:http://embed.plnkr.co/u18KQc/preview - 它应该以这种方式工作。它不处理好iframe内部。 –
这是在plnkr上工作,我说的是当我下载代码并在我的电脑上运行它,因为它不工作? – user2216267