【问题标题】:AngularJS routing in codepenCodepen中的AngularJS路由
【发布时间】:2018-11-19 16:24:48
【问题描述】:

https://codepen.io/a_shokn/pen/yEJpww?editors=1010

var myApp = angular.module('myApp', ['ngRoute']);

myApp.config(function ($routeProvider) {

    $routeProvider

    .when('/', {
        templateUrl: 'main.html'

    })

    .when('/second',{
         templateUrl:'second.html'

    })

});

这是我的代码片段的链接,我的问题是在 anjular js 中使用路由时,我们必须保留我们的文件(在我的情况下为 main.html 和 second.html)

【问题讨论】:

    标签: javascript angularjs routing ngroute codepen


    【解决方案1】:

    据我了解,codepen 不支持添加多个文件。您可以尝试将代码移至 plunker。或者,您可以尝试在 HTML 中使用内联模板。例如,要解析main.html,您可以在 HTML 中编写这个 sn-p:

    <script type="text/ng-template" id="main.html">
    // contents of main.html
    </script>
    

    这将使 AngularJS 使用 script 标签解析模板。您可以找到代码的工作演示 here

    【讨论】:

    • 会不会提供同样的功能
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-02
    • 1970-01-01
    • 2014-08-28
    • 2017-08-29
    • 1970-01-01
    • 2017-06-10
    相关资源
    最近更新 更多