1

So I have written two different angular js codes.

One contains module and controller. This looks like below and works well on my html file!

(function() {
  'use strict';
  angular
    .module('demo', [])
    .controller('repeatController', repeatController);

  function repeatController($scope) {

  }
})();

I, however, have these two js files like below. One only contains module, and the other has controller in it. I tested angularjs simply by using {{}} but it does not work on the html file. {{3+1}} appears to be {{3+1}} not 4.

(function(){

    angular
        .module('demo', [])

})(a);

and

(function() {

    angular
        .module('demo')
        .controller("repeatController", repeatController);

        function repeatController(){

        }

})();

Can anyone fix the bottom one?

1
  • The question lacks MCVE and cannot get a quality answer. The most obvious explanation is that you didn't look into the console - you will see errors there, because it won't fail silently in a situation like that. Commented Jul 22, 2016 at 23:13

1 Answer 1

1

Change first file like this E.g. app.js:

'use strict';

angular.module('demo', []);

And second:

(function() {
'use strict';
    angular
        .module('demo')
        .controller("repeatController", repeatController);

        function repeatController(){

        }

})();

Check this style guide: https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md

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

1 Comment

Now "use strict" is global, not a good idea if any other script that follows in page isn't compliant. Only problem ws using 2 module declarations for same module

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.