Alles funktionierte gut, bis ich versuchte, Routing hinzuzufügen. Ich habe gelesen, dass Angularjs Version 1.2+ 'ngRoute' als Abhängigkeit benötigt (ich benutze Version 1.2.16). Ich habe es hinzugefügt, aber es funktioniert immer noch nicht. Unten sind meine Codes.Angularjs Routing funktioniert nicht
test.html (Hauptseite)
<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>
Es gibt einen Link zu einem Bild von meinem Arbeitsverzeichnis: http://postimg.org/image/979tsaecd/ – yellowbyte
Sind Sie sicher, dass dies die richtige Syntax ist: demoApp.controller (Controller)? Ich kann keinen Hinweis darauf finden. – Yoeri
Ja, ich habe es in diesem Tutorial gesehen: https://www.youtube.com/watch?v=Uj-KLCTsQrw. – yellowbyte