AngularJS - controller and factory - where am I going wrong? -


i'm new angular , cannot pinpoint going wrong. i'm trying inject factory controller, reference said controller within html , use ng-repeat present data. can't work solely using handlebars , excluding ng-repeat. i'm here see if there glaringly wrong code i'm missing. i've been going through 2 separate tutorials hang on , sure had it. guess not though.

html:

<html data-ng-app='theapp'>  <div class='siderow' data-ng-controller='maintagcontroller'>  <div class='siderowlabel'>tags</div>  <div class='siderowdata'>  <a href='page.html' class='bluelink' data-ng-repeat='maintag in maintags'>{{ maintag }}</a>  </div>  </div> 

js:

/// <reference path="../../vendor/angular.min.js" />  var theapp = angular.module('theapp', []);  theapp.factory('maintagfactory', function() {       var maintags = [           { maintag: 'tag 1'},         { maintag: 'tag 2'},         { maintag: 'tag 3'},      ];      var factory = {};      factory.getmaintags = function() {           return maintags       }      return factory   });  theapp.controller('maintagcontroller', function ($scope, maintagfactory) {      init();       function init() {          $scope.maintags = maintagfactory.getmaintags();       }  }); 

seems missing semicolons inside factory function.

here can find working jsfiddle:

http://jsfiddle.net/me49s/

factory.getmaintags = function() {       return maintags   }  return factory  

i felt free replace {{ maintag }} {{ maintag.maintag }}, thought wanted achieve.

hope works you

pietro


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -