Uncaught TypeError: undefined is not a function please help

96 views
Skip to first unread message

Ryan McKinney

unread,
Feb 27, 2015, 10:11:33 AM2/27/15
to ang...@googlegroups.com
Hi, I am new to ionic framework and angularjs. I am experimenting to get my head around the launguage. I have cam across this error and I cannot figure out what is going wrong.

Uncaught TypeError: undefined is not a function lynasService.js:4.
I will paste my code below and if someone can tell me where I ahve went wrong it would be greatly appreciated.
Thanks in advance

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
    <script src="js/controllers.js"></script>
    <script src="js/services.js"></script>
    <script src="js/lynasService.js"></script>
  </head>
  <body ng-app="starter">
    <!--
      The nav bar that will be updated as we navigate between views.
    -->
    <ion-nav-bar class="bar-stable">
      <ion-nav-back-button>
      </ion-nav-back-button>
    </ion-nav-bar>
    <!--
      The views will be rendered in the <ion-nav-view> directive below
      Templates are in the /templates folder (but you could also
      have templates inline in this html file if you'd like).
    -->
    <ion-nav-view></ion-nav-view>
  </body>
</html>


lynasService.js


var app = angular.module('userCtrl', []);

app.Service("lynasService", function ($http, $q) {
    var deferred = $q.defer();
    $http.get('users.json').then(function (data) {
        deferred.resolve(data);
    });
    this.getUsers = function () {
        return deferred.promise;
    }
})

.controller("userCtrl", function ($scope, lynasService) {
    var promise = lynasService.getUsers();
    promise.then(function (data) {
        $scope.team = data;
        console.log($scope.team);
    });




});

tab-dash.html (template)

<!doctype html>
<html lang="en">
<body>
    <script src="js/lynasService.js"></script>

    <div class="mainContainer" data-ng-app="lynasService">
        <h1>LynasApp</h1>

        <div data-ng-controller="userCtrl">

        </div>
    </div>
</body>

</html>
<ion-view view-title="Dashboard">
  <ion-content class="padding">
    <!--<div class="list card">
      <div class="item item-divider">Recent Updates</div>
      <div class="item item-body">
        <div>
          There is a fire in <b>sector 3</b>
        </div>
      </div>
    </div>
    <div class="list card">
      <div class="item item-divider">Health</div>
      <div class="item item-body">
        <div>
          You ate an apple today!
        </div>
      </div>
    </div>
    <div class="list card">
      <div class="item item-divider">Upcoming</div>
      <div class="item item-body">
        <div>
          You have <b>29</b> meetings on your calendar tomorrow.
        </div>
      </div>
    </div>-->
      
  </ion-content>
</ion-view>

controller.js

angular.module('starter.controllers', [])

.controller('DashCtrl', function($scope) {})

.controller('ChatsCtrl', function($scope, Chats) {
  $scope.chats = Chats.all();
  $scope.remove = function(chat) {
    Chats.remove(chat);
  }
})

.controller('ChatDetailCtrl', function($scope, $stateParams, Chats) {
  $scope.chat = Chats.get($stateParams.chatId);
})

.controller('FriendsCtrl', function($scope, Friends) {
  $scope.friends = Friends.all();
})

.controller('FriendDetailCtrl', function($scope, $stateParams, Friends) {
  $scope.friend = Friends.get($stateParams.friendId);
})

.controller('AccountCtrl', function($scope) {
  $scope.settings = {
    enableFriends: true
  };
})




error.png
Reply all
Reply to author
Forward
0 new messages