0

所以我正在尝试使用AngularJS创建一个不需要网络服务器的应用程序

我使用<script type="text/ng-template" id="loginView.html" src="views/login.html"></script>标签来使用单独的模板并保持干净。

我把东西连接起来:

app.config(function($routeProvider, $locationProvider){
    $locationProvider.hashPrefix("!");
    $locationProvider.html5Mode(false);

    $routeProvider
        .when("/", {
            templateUrl: "loginView.html",
            controller: "LoginCtrl"
        })
        .when("/main", {
            template: "main",
            controller:"MainCtrl.html"
        })
        .otherwise({
            redirectTo: "/"
        });
});

我的文件没有加载。如果我将上下文放在脚本标签中,我可以看到它。我有一个 ng-view 来包含视图。但我似乎无法从单独的文件中获取内容。没有给出错误。如果没有网络服务器,这可能吗?

4

2 回答 2

2

Try using <div ng-view /> instead of your script. You can fetch the template just from your file system, you don't need to be on a web server.

于 2014-01-13T22:17:13.860 回答
0

你把那些脚本标签放在哪里?在 HTML 中?我什至不知道像这样的脚本标签会按照您的期望做,无论是有角度的还是其他的,但这不是必需的。您所做的调用$routeProvider.when足以加载 HTML 模板。不过,您将不得不反转/main路线的参数,因为您似乎将template/templateUrlcontroller反转了。templateUrl虽然在那里 使用。template用于原始 HTML。

于 2014-01-13T22:26:55.183 回答