gpt4 book ai didi

javascript - ng-template 不在 jsFiddle 中显示 View

转载 作者:行者123 更新时间:2023-11-30 16:26:13 25 4
gpt4 key购买 nike

我是从 here 学习 AngularJS View 的.该站点显示的示例应该输出:

output

然而,output未显示在 my fiddle 中:

         var mainApp = angular.module("mainApp", ['ngRoute']);
mainApp.config(['$routeProvider', function($routeProvider) {
$routeProvider.

when('/addStudent', {
templateUrl: 'addStudent.htm',
controller: 'AddStudentController'
}).

when('/viewStudents', {
templateUrl: 'viewStudents.htm',
controller: 'ViewStudentsController'
}).

otherwise({
redirectTo: '/addStudent'
});
}]);

mainApp.controller('AddStudentController', function($scope) {
$scope.message = "This page will be used to display add student form";
});

mainApp.controller('ViewStudentsController', function($scope) {
$scope.message = "This page will be used to display all the students";
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<h2>AngularJS <a href='http://www.tutorialspoint.com/angularjs/angularjs_views.htm'>ng-template example</a></h2>
<div ng-app = "mainApp">
<p><a href = "#addStudent">Add Student</a></p>
<p><a href = "#viewStudents">View Students</a></p>
<div ng-view></div>

<script type = "text/ng-template" id = "addStudent.htm">
<h2> Add Student </h2>
{{message}}
</script>

<script type = "text/ng-template" id = "viewStudents.htm">
<h2> View Students </h2>
{{message}}
</script>
</div>

我相信,我已经正确选择了LOAD TYPE:

LOAD TYPE

What am I doing wrong here?

最佳答案

为了让 ngRoute 工作,你必须添加:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>

问题是由于缺少包含 ngRoute 模块引起的

working example

关于javascript - ng-template 不在 jsFiddle 中显示 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34109461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com