一切正常,直到我尝试添加路由.我读到
Angularjs 1.2版需要“ngRoute”作为依赖(我使用的是版本1.2.16).我添加了它,但它仍然不起作用.以下是我的代码
test.html(主页)
<html ng-app="demoApp"> <head> <title></title> </head> <body> <p>Front Page</p> <div ng-view></div> <script src="angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-route.js"></script> <script src="testjs.js"></script> </body> </html>
testjs.js
demoApp = angular.module('demoApp',['ngRoute']); demoApp.config(function ($routeProvider) { $routeProvider.when('/',{ controller: 'SimpleController',templateUrl: '/partials/first.html' }); }); var controllers = {}; controllers.SimpleController = function ($scope){ $scope.first = "Info"; $scope.customers=[ {name:'jerry',city:'chicago'},{name:'tom',city:'houston'},{name:'enslo',city:'taipei'} ]; }; demoApp.controller(controllers);
first.html
<div> <input type="text" ng-model="name"/> </br> {{first}} </br> <ul> <li ng-repeat="cust in customers | filter:name">{{cust.name | uppercase}} - {{cust.city}}</li> </ul> </div>
这是最基本的设置可能,我会尝试用你的代码制作另一个:
http://plnkr.co/edit/sN9TagVBOdX3mkrxaTiu?p=preview
原文链接:https://www.f2er.com/angularjs/142549.htmlhttp://plnkr.co/edit/sN9TagVBOdX3mkrxaTiu?p=preview
EDIT用示例代码更新.一切似乎都在工作?
编辑2的问题是OP没有运行网络服务器. Ng-Route需要一个网络服务器才能正常运行.