0

I am trying to specify multiple values on the same module, but I cannot succeed. Is there something wrong with my code?

mod = angular.module("services", []);
mod.value("message","text1");
mod.value("message2","text2");

When I reference message in the HTML page it works, but when I try to use message2 it doesn't. What's happening?

EDIT: It worked when I changed the controller from

angular.module("root",["services"])
    .controller("index", ["$scope", "message", function($scope, message){
        $scope.message = message;

    }]);

to

angular.module("root",["services"])
    .controller("index", ["$scope", "message", function($scope, message){
        $scope.message = message;

    }])
    .controller("index2", ["$scope", "message2", function($scope, message2){
        $scope.message2 = message2;

    }]);
1
  • 1
    Are you sure to inject both Value services in the controller related to the html template? Commented May 19, 2014 at 20:01

2 Answers 2

2

There isn't something wrong. It works fine !
Probably some type in your code.

Make sure you inject them correctly:

.controller('someCtrl', function ($scope, message, message2) {
    console.log(message, message2);
});
Sign up to request clarification or add additional context in comments.

Comments

1

Makesure to inject both Value services in the controller

controller

controller('Ctrl', function($scope, message, message2) {
    $scope.message = message;
    $scope.message2 = mesage2;
  })

html

<div ng-controller="Ctrl">
   <p>{{message}}</p>
   <p>{{message2}}</>
</div>

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.