AngularJS:未捕获错误:无模块:GridCambiable

时间:2015-10-21 12:16:31

标签: javascript json angularjs

我正在尝试跟进我在http://jsfiddle.net/scyrizales/pC9dH/

找到的教程和演示

因此,这是我所做的代码片段

<div ng-app="GridCambiable" ng-controller="GridCambiableController">

    <div class="bar">

        <!-- These two buttons switch the layout varaible,
             which causes the correct UL to be shown. -->

        <a class="list-icon" ng-class="{active: isLayout('list')}" ng-click="setLayout('list')"></a>
        <a class="grid-icon" ng-class="{active: isLayout('grid')}" ng-click="setLayout('grid')"></a>
    </div>

    <!-- We have two layouts. We choose which one to show depending on the "layout" binding -->

    <ul ng-show="isLayout('grid')" class="grid">
        <!-- A view with big photos and no text -->
        <li ng-repeat="p in pics">
            <a href="{{p.link}}" target="_blank"><img ng-src="{{p.images.low_resolution.url}}" /></a>
        </li>
    </ul>

    <ul ng-show="isLayout('list')" class="list">
        <!-- A compact view smaller photos and titles -->
        <li ng-repeat="p in pics">
            <a href="{{p.link}}" target="_blank"><img ng-src="{{p.images.thumbnail.url}}" /></a>
            <p>{{p.caption.text}}</p>
        </li>
    </ul>

app.controller('GridCambiableController', ['$scope', 'instagram' ,
function ($scope, instagram){

    // Layout por defecto

    $scope.layout = 'grid';

    $scope.setLayout = function(layout){
        $scope.layout = layout;
    };

    $scope.isLayout = function(layout){
        return $scope.layout == layout;
    };

当我启动代码时,我在Chrome控制台上收到此错误

Uncaught Error: No module: GridCambiable

我已经尝试了一下 http://plnkr.co/edit/9BYKw45ZrIgVpbixRsAz?p=preview

请问我为什么要在我的控制台上看到这个。 感谢。

2 个答案:

答案 0 :(得分:0)

在你的控制器之前添加:

var app = angular.module(“GridCambiable”,[]);

替代方案:

angular.module(“GridCambiable”,[])。controller('GridCambiableController',['$ scope','instagram', 功能($ scope,instagram){

// Layout por defecto

$scope.layout = 'grid';

$scope.setLayout = function(layout){
    $scope.layout = layout;
};

$scope.isLayout = function(layout){
    return $scope.layout == layout;
};

答案 1 :(得分:0)

在您加入script.js之后,您没有包含angular.min.js

在index.html中:

<!--include angular-->
<script src="script.js"></script>