0

First of all, i'm discovering AngularJS. I read many courses about it but i'm far from being familiar with it.

I have a project, were i cannot modify the previous declarations. I want to add wysiwyg into the project.

I have to create an other controller using the existant module. I know that if i redefine the module, previous will be lost.

I thought this would be good :

angular.module('demo')
  .controller('WysiwygCtrl', ['colorpicker.module', 'wysiwyg.module', function($scope) {
    $scope.data = {
      text: "hello"
    }
}]);

But it doesn't work.

In fact, the easiest way would be :

angular.module('demo', ['colorpicker.module', 'wysiwyg.module'])
  .controller('WysiwygCtrl', function($scope) {
    $scope.data = {
      text: "hello"
    }
});

But it creates a new module and i loose previous one ...

How can i do to make it works ? If you need more code i can edit my question just ask but i think the module/controller is the most important part.

Thanks for you help, i'm facing this problem since this morning.

EDIT1 : The wysiwyg library is hosted on github here https://github.com/TerryMooreII/angular-wysiwyg

EDIT2 : Right now, nothing is displayed because i have the following error : Error: [$injector:unpr] http://errors.angularjs.org/1.2.16/$injector/unpr?p0=colorpicker.moduleProvider%20%3C-%20colorpicker.module

6
  • So are you saying you want to access the wysiwyg.module within the WysiwygCtrl controller code? Commented Feb 10, 2015 at 12:29
  • @mindparse i don't know ... This code works : var app = angular.module('app', ['colorpicker.module', 'wysiwyg.module']) app.controller('MyCtrl', function($scope) { $scope.data = { text: "hello" } }) Now i'd like to know why mine isn't working Commented Feb 10, 2015 at 12:31
  • So what exactly is not working? Are you seeing the 'hello' appear in the wysiwyg editor? Commented Feb 10, 2015 at 12:35
  • You don't know? This is a really confusing question, can you share more of your codes Commented Feb 10, 2015 at 12:35
  • Ok i'm going to edit my post and give you more informations, thanks for the help Commented Feb 10, 2015 at 12:36

3 Answers 3

2

angular.module('moduleName', ['dep1', 'dep2']) - creates a module, that has dependencies listed in a second parameter, this signature also returns newly created module, you HAVE to specify list of dependencies, even if it's just an empty array []. This also overwrites any existing modules by the same name.

angular.module('moduleName') - returns a module created earlier in your code, hence the absence of dependency list in the signature - this also returns a module.

both signatures allow you to add controllers, services, etc..

Sign up to request clarification or add additional context in comments.

7 Comments

ok, but knowing that i can't modify the module before, is there a way to add dependencies ? ['colorpicker.module', 'wysiwyg.module'] ?
@Maxime - no, you have to specify all dependencies up front
Damn ... The best way would have been to declare the module, save it in a var and use that var after .... but here ? It's a big mess and i'm lost
yes, both signatures allow you to save module to a var, but you can't add more dependencies to an existing module.. and you don't need to!!
@Maxime glad to be able to help.
|
1

Plus I think you need to be passing in references to them modules in the function

.controller('WysiwygCtrl', ['$scope', 'colorpicker.module', 'wysiwyg.module', function($scope, colorpickermodule, wysiwygmodule) {
    $scope.data = {
      text: "hello"
    }
}

1 Comment

Error: [$injector:unpr] http://errors.angularjs.org/1.2.16/$injector/unpr?p0=colorpicker.moduleProvider%20%3C-%20colorpicker.module
0

If you use the array notation when creating components as controllers or directives, then the parameters on the main function or module should match. As i see that you use

.controller('WysiwygCtrl', ['colorpicker.module', 'wysiwyg.module',   function($scope) {
$scope.data = {
  text: "hello"
}

you maybe want to say

.controller('WysiwygCtrl', ['$scope', 'colorpicker.module', 'wysiwyg.module', function($scope) {
$scope.data = {
  text: "hello"
}

2 Comments

I tried to add the '$scope' but i still have an error : Error: [$injector:unpr] http://errors.angularjs.org/1.2.16/$injector/unpr?p0=colorpicker.moduleProvider%20%3C-%20colorpicker.module
It seens like it can't find the colorpicker.module service. You have to make sure that you declare it before trying to inject it into another component as a dependency

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.