控制器&工厂AngularJS

时间:2015-04-07 06:58:43

标签: angularjs

这是一个教育性的帖子。 我试图理解为什么我的plunker在这里不起作用。我只想将facotry连接到控制器,然后使用ng-repeat导入数据。

我尝试了几种语法,但无法编写正确的实现。 Tahnks为你提供帮助。

控制器:

   var wmapp = angular.module('wmapp' []);

  .controller('restaurantlistController', function ($scope, $rootScope, restaurantsFactory) {
    "use strict";
    $scope.restaurantList = restaurantsFactory.getRestaurants(); //call to restaurantfactory
})

工厂:

angular.module('wmapp.factory_restaurants', [])

.factory('restaurantsFactory', function () {
    "use strict";
    var factory = {
            Restaurants : [
                {Name: 'A La Biche Au Bois', venueType: 'Restaurant ',  subCuisine: 'Italian',  subsubCuisine: 'Classic/traditional', address: '45 Avenue Ledru-Rollin', cp: '75012', city: 'Paris', country: 'France', countryCode: 'FR', itemid: 'PARIREST002', phoneNumber: '+331 43 43 34 38', website: '', lat: 48.8482040, long: 2.3706140, icon: 'img/restaurant_pointer_WMcustom_40x49_v3.png'},
                {Name: 'Allard   ', venueType: 'Restaurant ',  subCuisine: 'French',  subsubCuisine: 'Classic/traditional', address: '41, rue Saint-André des Arts', cp: '75006', city: 'Paris', country: 'France', countryCode: 'FR', itemid: 'PARIREST004', phoneNumber: '+33158002342', website: 'http://www.restaurant-allard.fr/en', lat: 48.8532490, long: 2.3409810, icon: 'img/restaurant_pointer_WMcustom_40x49_v3.png'},
                {Name: 'Ambassade d\'Auvergne', venueType: 'Restaurant ',  subCuisine: 'French',  subsubCuisine: 'Auvergne region', address: '22 Rue du Grenier Saint-Lazare', cp: '75003', city: 'Paris', country: 'France', countryCode: 'FR', itemid: 'PARIREST005', phoneNumber: '+331 42 72 31 22', website: 'http://www.ambassade-auvergne.com/', lat: 48.8631310, long: 2.3534140, icon: 'img/restaurant_pointer_WMcustom_40x49_v3.png'}

  // more restaurans



            ],
            getRestaurants : function () {
                return factory.Restaurants;
            },
        };
    return factory;

});

html:

  <div data-ng-controller="restaurantlistController" ng-repeat="restaurant in restaurantList " href="#">
    <article class="item_frame">
      <div class="marker_left_container">
        <img class="venue_rest_marker" ng-src="{{restaurant.icon}}" />
        <span class="venu_type_text">{{restaurant.venueType}}</span>
        <span class="distance_from_user_rest">0.7 km</span>
        <span class="distance_from_user_rest2">from current location</span>
      </div>
      <div class="restaurant_details_container">
        <h1 class="restaurant_name_inlist">{{restaurant.Name}}</h1>
        <span class="restaurant_detail_inlist2">{{restaurant.subCuisine}}                            <br />

      {{restaurant.subsubCuisine}}</span>
        <span class="restaurant_address">{{restaurant.address}},                             <br />
        </span>
        <span class="restaurant_address">{{restaurant.cp}}, {{restaurant.city}}                             <br />
          <br />
        </span>
        <span class="restaurant_others">{{restaurant.phoneNumber}}                            <br />
        </span>
        <span class="restaurant_others">{{restaurant.website}}                            <br />
          <br />
        </span>
      </div>
    </article>
    <!--main article frame 1 -->
  </div>

1 个答案:

答案 0 :(得分:0)

有4个以上的错误,主要是semicolon , dots , module不包含错误 检查此链接现在是否正常plunker

相关问题