Building a solid foundation for web applications involves organizing angularjs components such as controllers, services, and more into

Just starting out with Foundation for Apps, I encountered an issue when trying to organize my angular controllers in a separate folder and use them.

In the js folder of my assets directory, I currently have this structure:

js/
   app.js //contains all controllers by chaining

but what I want is:

js/
   app.js
   controllers/
       home.controller.js
       main.controller.js

Instead of having one large js file with chained controllers and services, I prefer a more modular structure as described above.

After switching to the modular structure, I encountered three errors:

1. 'HomeCtrl' not defined.
2. Uncaught SyntaxError: Unexpected token < at the 1st line of home.controller.js
3. Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:8079/assets/js/home.controller.js". when including 'home.controller.js' in index.html

Here's my template:

---
name: home
url: /
controller: HomeCtrl
---

<div class="grid-container">
  <h1>Welcome to Foundation for Apps!</h1>
  <p class="lead">This is version <strong>1.1 Weisshorn</strong>.</p>
</div>

home.controller.js:

app.controller('HomeCtrl', ['$scope', function($scope) {
    $scope.temp = 'hello';
}]);

app.js:

var app = angular.module('application', [
  'ui.router',
  'ngAnimate',
  'foundation',
  'foundation.dynamicRouting',
  'foundation.dynamicRouting.animations'
])
  .config(config)
  .run(run)
;

config.$inject = ['$urlRouterProvider', '$locationProvider'];

function config($urlProvider, $locationProvider) {
  $urlProvider.otherwise('/');

  $locationProvider.html5Mode({
    enabled:false,
    requireBase: false
  });
}

function run() {
  FastClick.attach(document.body);
}

To resolve this issue, I attempted adding the controller reference in gulpfile.js following this guide.

I also looked into this resource but still cannot get it to work. Any insights on what I might be missing?

Answer №1

Check the gulpfile.js for more details at this specific line. It appears that only client/assets/js/app.js is being utilized when integrating your minimized file. To ensure all your controller files with a .js extension are also included, you must update it to copy them as well:

// These files are for your app's JavaScript
appJS: [
    'client/assets/js/app.js',
    './client/assets/js/controllers/*.js',
]

Another approach is using an angular module to manage all your controllers and services, then injecting it into your app module. Here's how I implement it in my project at this location, and this method is also demonstrated in this useful Fork repository: https://github.com/CreativityKills/foundation-apps-template

  • Note: remember to restart gulp after each modification of its configuration file and verify if your code has been properly included in the built JS file (which defaults to /build/assets/js/app.js)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I use React to create a dictionary that modifies several values depending on a single property?

I am looking for a more efficient way to handle the following code in my component example. I have a list component that can display different types of animals such as dogs, cats, and bunnies with specific visual changes and functionality from the API. exp ...

Enhancing the efficiency of typed containers in JavaScript

Recently, I uncovered a clever method for creating fake 'classes' in JavaScript, but now I'm curious about how to efficiently store them and easily access their functions within an IDE. Here is an example: function Map(){ this.width = 0 ...

Tips for adding a new column to a website

My goal is to inject some custom HTML and CSS into YouTube in order to create a column on the right side that shifts all content towards the left. Essentially, I am trying to replicate the functionality of the Inspect Tool in Chrome. I am working on a Chr ...

What is the process of changing a number to the double data type in JavaScript or TypeScript?

Within a single input field, users can enter various numbers such as 12, 12.1, 12.30, and 12.34. The challenge is to pass this value in a service call where only the value can be sent as a number but with two decimal points. let a = input //a will be a ty ...

How can a regular number be used to create an instance of BigInteger in jsbn.js?

I attempted both methods: const num1 = new BigNumber(5); And const num2 = new BigNumber(7, 10); However, I encountered the following error: Error: 'undefined' is not an object (evaluating 'num2.nextBytes') bnpFromNumberjsbn2.js:126 ...

"Enhancing a many-to-many relationship with indexing in TypeORM: A step-by-step guide

Is it possible to add an index to the relation columns when creating a many-to-many relationship in typeORM entities? @Entity() export class Tag { @Column() id: number //@Index() does not work here... @ManyToMany(() => Todo, (todo) => todo ...

Discovering Constraints on File Size: API Response Encoded in Base64 Visible Within 1 Megabyte, Overcoming Rendering Obstacles

Currently, I am encountering a hurdle in my Next.js application when trying to upload images larger than 1 MB. While the app works seamlessly with smaller images, it faces challenges when dealing with larger ones. Initially, there was a browser console er ...

Transferring Information between a Pair of Controllers

Currently, I am utilizing angular version 1.x and faced with the challenge of sharing data between two controllers. In my mainctrl, I am working with the above model. The radiotmplt.radiohead=='IRU600v3' is utilized in firstctrl. Unfortunately, ...

AngularJs: uncomplicated rating system

Is there a way to increase a variable in an ng-repeat loop when clicked? <li class="item" ng-repeat="post in posts"> ... ... <button ng-click="incrementLike(post.like_count)">Like {{post.like_count}}</button> ... ... </li> $scope ...

Syncronizing browsers, automating tasks with Gulp, using MongoDB, and

I need assistance with setting up a project that involves running an express server along with gulp, browsersync, nodemon, and mongodb. I'm encountering an Error: listen EADDRINUSE when trying to add browsersync. Any suggestions on how to resolve this ...

AngularJS has declared a variable as undefined

After successfully completing a tutorial on AngularJS (available here: https://github.com/felipedaraujo/saturn-quiz), I decided to expand the app by adding a quiz about the planet Earth. This way, users can now select quizzes based on different planets. E ...

Connection between overlay div and corresponding destination div address

I created a linked image with an overlay div: <div class="imageBlock"> <a href="http://www.google.com"> <img src="https://placeimg.com/640/480/any"> </a> <a href="http://www.twitter.com"> <img src="https://pl ...

Having issues with using the class selector in SVG.select() method of the svg.js library when working with TypeScript

Exploring the capabilities of the svg.js library with typescript has presented some challenges when it comes to utilizing CSS selectors. My goal is to select an SVG element using the select() method with a class selector. In this interactive example, this ...

Debugging ImageMapster: troubleshooting jQuery/HTML problems

I am currently experiencing difficulties with the implementation of the jquery plugin known as ImageMapster. To assist in troubleshooting, ImageMapster has provided a demonstration through jsfiddle which can be accessed here: http://jsfiddle.net/nYkAG/396/ ...

Activating ng-change in AngularJS through ng-model

According to the information provided on w3schools website: The ng-change event will only be activated if there is an actual alteration in the input value, not if the change was executed through JavaScript. Therefore, when I set up ng-model using $scop ...

Tips for seamless communication between PHP and JavaScript

While working on my revolutionary WebIDE, I encounter numerous questions that challenge me. The goal of this project is to assist users in quickly developing what they normally would, but automated. One particular question I have is regarding the implement ...

Encountering an error: "Unhandled promise rejection SyntaxError: Unexpected character in JSON data at line 1 column 1."

When the submit button is clicked, my registration form data is sent using an event function called postData() in React. The user data is sent at the register route, and I have mentioned line numbers in the comments: const postData = async(event) =>{ ...

Is there a way to change an element's display to 'block'? (see more information below)

I'm having an issue with my event listener for a button that is supposed to change the css of #popUpForm. It seems to only work when I add inline css directly to #popUpForm. Is there a way to achieve this without using inline css and instead setting t ...

Ways to generate an Angular 7 component

Seeking guidance on creating an angular 7 component. I have forked a jsFiddle at this link: https://jsfiddle.net/gauravshrestha/fdxsywLv/. The chart in the fiddle allows data points to be dragged up and down. My goal is to convert this into a component whe ...

Angular tutorial: Organizing data by date only

This is my first time building an Angular app. I am fetching JSON data from an API using a factory service to get football match fixtures. My goal is to group these fixtures by date while disregarding the time component. The date string in the JSON is fo ...