Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Anthony Domina
PLUS
Anthony Domina
Courses Plus Student 19,571 Points

Problem using angular module in multiple html files

Here is my js file. I have a page called Japan.html and it uses this file to pull the js objects below into a carousel. It works great! The problem is when I try to do the same for China.html.

 var app = angular.module("JapanLocationApp", []);

app.controller("jlCtrl", function($scope) {
  $scope.japanLocations = [
       {name: 'Jigokudani',
        image: 'img/Jigokudani.jpg',
        description: 'See the famous snow monkeys in their native habitat!',
        url: "Jigokudani.html"},

        {name: 'Kagoshima',
        image: 'img/Kagoshima.jpg',
        description: "Take a day trip from here to Sakurajima and behold the world's largest radish!",
        url: 'Kagoshima.html'},

        {name: 'Nikko',
        image: 'img/Nikko.jpg',
        description: "It is here that the ashes of Tokugawa Ieyasu have been enshrined",
        url: 'Nikko.html'},

         {name: 'Kamakura',
        image: 'img/Kamakura.jpg',
        description: "The country's 2nd largest Buddha is just a short trip from Yokohama",
        url: 'Kamakura.html'},

        {name: 'Nagoya',
        image: 'img/Nagoya.jpg',
        description: "Home of Toyota, and while you're here, try the Kishimen, it's delicious!",
        url: 'Nagoya.html'},

  ]

});

here is my html

<!DOCTYPE html>
<html ng-app="JapanLocationApp">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>Japan Travels</title>
    <!-- bootstrap css -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="js/slick/slick.css"/>
   <link rel="stylesheet" type="text/css" href="js/slick/slick-theme.css"/>
       <link rel="stylesheet" href="css/normalize.css">
           <link rel="stylesheet" href="css/main.css">

  </head>


  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>



  <body ng-controller="jlCtrl">
  <div class="wrap">
    <header class="main-header">
    <!-- navbar --> 
    <nav class="navbar fixed-top navbar-toggleable-md navbar-inverse bg-primary">
  <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item">
        <a class="nav-link" href="about.html">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="about.html">About</a>
      </li>
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle active" href="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          World Travel
        </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
          <a class="dropdown-item" href="#">Canada</a>
          <a class="dropdown-item" href="China.html">China</a>
          <a class="dropdown-item" href="Japan.html">Japan</a>
          <a class="dropdown-item" href="#">Mexico</a>
          <a class="dropdown-item" href="#">South Korea</a>
          <a class="dropdown-item" href="#">Thailand</a>
          <a class="dropdown-item" href="#">Turkey</a>
        </div>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#usa">USA Travel</a>
      </li>
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">日本語練習</a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
          <a class="dropdown-item" href="QuizNihongo.html">単語</a>
          <a class="dropdown-item" href="QuizGiongoGitaigo.html">擬音語と擬態語</a>
        </div>
      </li>
    </ul>
    <a class="navbar-brand hidden-xs-down" href="http://www.teamtreehouse.com">Tony Domina, Designer</a>
  </div>
</nav>
    <!-- /navbar -->

    </header>
<h1 id="speakers" class="display-4 text-center my-3 text-muted">Come see where I've been in Japan!</h1>

<div class="container">
      <!-- speakers -->
<div class="row JLcenter">
  <div class="col-md-6 col-lg-4"  ng-repeat="x in japanLocations | orderBy: 'name'">
    <div class="card cardPop">
    <a href={{x.url}}>
    <img class="card-img-top img-fluid" src={{x.image}} alt="Card image cap">
    </a>
    <div class="card-block">
      <h4 class="card-title">{{x.name}}</h4>
      <p class="card-text">{{x.description}}</p>

    </div>
  </div>
  </div>
</div><!-- /speakers -->
</div>



      <footer class="main-footer">
        <a href="https://teamtreehouse.com"><img src="img/twitter-wrap.png" alt="Twitter Logo" class="social-icon"></a>
       <a href="https://teamtreehouse.com"><img src="img/facebook-wrap.png" alt="Facebook Logo" class="social-icon"></a>
        <p>&copy; 2017 Tony Domina.</p>
      </footer>
   </div>
   <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>

<script src="js/japaneseLocation.js"></script>
 <script type="text/javascript" src="js/slick/slick.min.js"></script>
<script>
$(document).ready(function(){
   $('.JLcenter').slick({
  autoplay: true,
  autoplaySpeed: 3000,
  dots: true,
  centerMode: true,
  centerPadding: '60px',
  slidesToShow: 3,
  arrows: true,
  responsive: [
    {
      breakpoint: 768,
      settings: "unslick"
    },
    {
      breakpoint: 480,
      settings: "unslick"
    }
  ]
 });
});
</script>


  </body>
</html>

If anyone wants to see what the Japan page actually looks like it can be found at be-tony.com/Japan.html

Please share if you know how can replicate this functionality in a China.html page. Can I have two controllers in the same file? One of China and one for Japan? Can both html pages reference the same app and then just point at the different controllers? I've tried this and it does not work.