0

我是网络编程新手。现在我正在使用 ionic 开发一个应用程序,其中主要专注于使用 angularjs。我只是想问一些愚蠢的问题。

我的应用程序的情况是有链接到不同 url (.html) 的 img 链接列表,其中页面中只包含单词(这些页面是另一个网站,我无法更改任何内容)。我只想先导航到一个新页面并显示这些内容并从 url(.html) 做一些 css 样式。只能在不使用 ajax 而使用 angularjs 的情况下这样做吗?有没有这样做的演示?

****编辑版**** 我的想法和本教程一模一样(包括源代码):http://css.dzone.com/articles/tutorial-how-create-responsive?page=0, 2

还有现场演示:http ://www.script-tutorials.com/demos/359/index.html#!/

但这里的源代码只是指相对路径 url,如<a class="xxx" href="#!/project/product1" style="background-color:#87b822"/a>.
我可以参考其他网站 href="http://justinjackson.ca/words.html,并在我的页面中为这些内容添加一些 css 样式吗?

4

1 回答 1

0

有几种方法可以做到这一点

1-ng-包括

您可以使用条件 ng include like,在这里您可以更改 v

<div ng-include="x ? 'your-html-file.html' : null"></div>

例如 x 在范围内

$scope.x = false;
$scope.setX = function(){$scope.x=true;}

在 img 点击

  <img ng-click="setX()">

2-路由

您可以使用 Routing ,您可以下载 angular route 并通过将其注入模块来使用它

将其包含在您的索引页面中

<script src="js/angular-route.js"></script> 

制作页面文件夹并在其中制作您的页面/部分模板

现在在 app.js 中你可以像这样定义你的路由

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

    // configure our routes
    youApp.config(function($routeProvider) {
        $routeProvider

            // route for the home page
            .when('/', {
                templateUrl : 'pages/home.html',
                controller  : 'mainController'
            })

            // route for the about page
            .when('/about', {
                templateUrl : 'pages/about.html',
                controller  : 'aboutController'
            })

            // route for the contact page
            .when('/contact', {
                templateUrl : 'pages/contact.html',
                controller  : 'contactController'
            });
    });
于 2014-12-12T20:08:31.720 回答