1

Day 4 of me learning AngularJs. So I decided to add AngularUI Bootstrap to my little project because Bootstrap is awesome if you don't already know that. Of course, it didn't work on the first go. I'm getting the error mentioned in the title, and the console isn't telling me much else.

Searching for others with similar problems tells me that it might be something to do with the order of the scripts loading in the <head> of my markup. Well I tried rearranging it as per the instructions I read and that didn't help much. Here's my code, what is wrong with it?

index.html

<!DOCTYPE html>
<html ng-app="navApp" ng-strict-di>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" />
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="../../assets/js/html5shiv.js"></script>
      <script src="../../assets/js/respond.min.js"></script>
    <![endif]-->

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-resource.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.5.0/ui-bootstrap-tpls.min.js" type="text/javascript"></script> 
    <script src="~/Areas/AngularTest/scripts/app.js"></script>



</head>
<body ng-cloak>
    <div ng-controller="menuController">
        <div ng-include="scripts/templates/sidebar.html"></div>
    </div>
</body>
</html> 

I'm using Grunt to combine my js files into one app.js so here are the separate pieces.

scripts/controllers/navController.js

var navApp = angular.module('navApp', [
    'ngResource',
    'ui.bootstrap',
    'ngAnimate'    
]);


navApp.controller('menuController', [
    '$scope',
    'navSectionList',
    'navGetCategories',

    function ($scope, navSectionList, navGetCategories) {
        $scope.navSectionList = navSectionList.query();
        $scope.getSectionID = function (event) {

            var sectionID = event.currentTarget.attributes["data-id"].value;
            $scope.sectionID = sectionID;

            $scope.navGetCategories = navGetCategories
                .getResource(sectionID)
                .query();

        };
    }
],
    function ($scope) {
        $scope.oneAtATime = true;
        $scope.status = {
            isFirstOpen: true,
            isFirstDisabled: false
        };
    }

);

scripts/services/navService.js

navApp.factory('navSectionList', [
    '$resource', function ($resource) {
        return $resource('/api/navigation/section/list', {}, {
            query: { method: 'GET', params: {}, isArray: true }
        });
    }
]);

navApp.factory('navGetCategories', ['$resource', function ($resource) {
    var service = {
        getResource: function (sectionID) {
            return $resource('/api/navigation/category/' + sectionID, {}, {
                query: { method: 'GET', params: {}, isArray: true }
            });
        }
    };
    return service;

}]);

templates/sidebar.html

<div class="sidebar">
    <uib-accordion close-others="oneAtATime">
        <div uib-accordion-group class="panel-default" heading="Products" is-open="status.isFirstOpen" is-disabled="status.isFirstDisabled">
            <ul>
                <li>New Arrivals</li>
                <li>On Sale</li>
            </ul>
        </div>
        <div uib-accordion-group class="panel-default" heading="{{section.name}}" ng-click="getSectionID($event)" ng-repeat="section in navSectionList" data-id="{{section.id}}">
            <ul>
                <li ng-repeat="categories in navGetCategories">
                    {{categories.name}}
                </li>
            </ul>
        </div>
    </uib-accordion>
</div>

Spot any problems? Well of course there's something wrong otherwise we wouldn't be here.

I wouldn't know where to start with the debugging, because at this point of time in my learning I'm mostly doing cargo-cult programming but we all have to start somewhere. teach me please.

1 Answer 1

1

Well that must be the fastest I've figured out something after asking a question. So there are a number of things wrong with my code above.

A. I called for ngAnimate but did not include the js. That was the main problem that resulted in the error message. Duh. Adding the following in the <head> fixed that problem.

https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular-animate.min.js

B. My ngInclude directive was not written properly. Note the missing src attribute and the lack of single quotes within double quotes. Both would result in the file not being included. The proper code is below:

<div ng-include src="'templates/sidebar.html'"></div>

C. My stylesheet was not declared proper. The right way to do it:

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" />

I'll start another thread regarding a new problem I'm getting with this code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.