Hi Marc
var app = angular.module('angularJsApp',[
'ngRoute',
'Post'
]
);
is wrong. Services etc you write are not external dependencies so don't try
to inject them when instantiating the app.
Instead app.hjs should look like this
var app = angular.module('angularJsApp',[
'ngRoute',
]
);
Marc
On Saturday, February 22, 2014 5:22:23 PM UTC+1, Marc B wrote:
>
> Hello,
>
> I am unable to add a a service in an angular app. I get this error:
>
> Error: [$injector:modulerr] Failed to instantiate module angularJsApp due
> to: [$injector:modulerr] Failed to instantiate module Post due to:
> [$injector:nomod] Module 'Post' is not available! You either misspelled the
> module name or forgot to load it. If registering a module ensure that you
> specify the dependencies as the second argument.
>
> I add the serice to the app definition dependecies when defining the
> angular app and added it to the contoller using inline array notation. What
> am I doing wrong here? Sorry for lots of code, hopefully it clarifies.
>
>
> index.htm:
>
> <!-- build:js({.tmp,app}) scripts/scripts.js -->
> <script src="scripts/app.js"></script>
> <script src="scripts/controllers/posts.js"></script>
> <script src="scripts/services/post.js"></script>
>
>
> app.js:
>
> 'use strict';
>
> var app = angular.module('angularJsApp',[
> 'ngRoute',
> 'Post'
> ]
> );
>
>
> scripts/controllers/posts.js
>
> 'use strict';
> angular.module('angularJsApp')
> .controller("PostsCtrl",['$scope','Post', function($scope,Post) {
> $scope.posts = [];
> $scope.post = {title:'',url:'http://'};
> $scope.addPost = function(){
> $scope.posts.push($scope.post);
> $scope.post = {title:'',url:'http://'};
> };
> $scope.deletePost = function(key){
> $scope.posts.splice(key,1);
> };
> $scope.resetPost = function(){
> $scope.post = {title:'',url:'http://'};
> };
> }]);
>
>
> scripts/services/post.js
>
> angular.module('angularJsApp')
> .factory("Post",function($resource){
> return $resource("https://firelab.firebaseio.com/posts/:id.json");
> });
>
>
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.