0

I use angularjs seed and trying to write a simple factory and insert it in to the controller.

I have a Row factory definition

angular.module('myApp')
.factory('Row', [ function () {
 return 'some string';
 ); 
}])

inside my view1 controller I have

'use strict';

angular.module('myApp.view1', ['ngRoute'])

.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/view1', {
templateUrl: 'view1/view1.html',
controller: 'View1Ctrl'
});
}])

.controller('View1Ctrl', ['$scope', 'Row', function($scope, Row) {
}]);

And I am getting an error it's not finding the Row factory.

2 Answers 2

1

Your factory should be using myApp.view1 module as myApp module is not defined.

angular.module('myApp.view1')
.factory('Row', [function() {
    return 'some string';
}])

Update

If you wanted to create a new module and append factory to it, then you should create a new module and include the previous dependency inside the [] array.

angular.module('myApp', ['myApp.view1'])
.factory('Row', [function() {
    return 'some string';
}])

Note: this JS should be loaded after the factory JS in order to make myApp.view1 available.


It seems like you are returning only string value form your factory. I'd say rather than having factory, you could make constant/ value. Out of which making constant would be preferred way of doing it. As it will be available in config phase as well.

angular.module('myApp.view1')
.constant('Row', 'some string');
Sign up to request clarification or add additional context in comments.

2 Comments

one extra close parenthesis is there strike it out
I change it to 'myApp.view1' but I am still getting an error. Unknown provider: RowProvider <- Row <- View1Ctrl
0

Tell "myApp.view1" to use "myApp".

angular.module('myApp.view1', ['ngRoute', 'myApp'])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.