0

Hello I have tried many ways to initialize a basic app but I do not know what it is wrong. The logic is the following

I "append" the following html containing the angular js module using a jquery ajax call.

('submit', function () {
        $.ajax({
            type: form.attr('method'),
            url: form.attr('action'),
            data: form.serialize(),
            success: function (data) {
                result.html(data);

Then the following html is loaded together with angularjs and the script having the module and controller definitions

HTML:

Load angular.js and the script where angular app is defined I type data-ng-app="app" in Body, HTML or wherever then data-ng-controller="controller" in a div or wherever i want to work on with the scope. Which should be already enough to initialize the controller. Am I right?

SCRIPT:

var app = angular.module('app', []);
app.controller('controller', ["$scope", "$http", function ($scope,$http) {

    console.log('works');

    ...more stuffs
]);

I have tried to copy paste from the most basics examples in tutorials but still not working. No problems with dependencies or syntax errors. What can be the problem?

Thanks in advance

6
  • You will need to add some more of your code that will allow someone to reproduce it in a minimal way. Commented Sep 19, 2016 at 20:08
  • Add your html complete please Commented Sep 19, 2016 at 20:08
  • you would immediately see problems with this code just by running it and opening the console! Commented Sep 19, 2016 at 20:18
  • Could be that the whole html is comes from a jquery Ajax call? Commented Sep 19, 2016 at 21:34
  • You can take this demo as a reference, it has the same problem plnkr.co/edit/FFjoTen5fZhptNfaV0wq?p=preview Commented Sep 19, 2016 at 21:36

1 Answer 1

1

The issue i see with your code is you are not passing the dependencies to your function

app.controller("listController", ["$scope", "$http"
    function($scope,$http) {         
         console.log('works');         
}]);

DEMO APP

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

3 Comments

sorry i missed that. it is there
Check the demo link I added
the angular app is loaded correctly but the controller is not initialized

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.