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
-
You will need to add some more of your code that will allow someone to reproduce it in a minimal way.Mike Cheel– Mike Cheel2016年09月19日 20:08:20 +00:00Commented Sep 19, 2016 at 20:08
-
Add your html complete pleasexzegga– xzegga2016年09月19日 20:08:33 +00:00Commented Sep 19, 2016 at 20:08
-
you would immediately see problems with this code just by running it and opening the console!Sam Redway– Sam Redway2016年09月19日 20:18:18 +00:00Commented Sep 19, 2016 at 20:18
-
Could be that the whole html is comes from a jquery Ajax call?ddomingo– ddomingo2016年09月19日 21:34:58 +00:00Commented Sep 19, 2016 at 21:34
-
You can take this demo as a reference, it has the same problem plnkr.co/edit/FFjoTen5fZhptNfaV0wq?p=previewddomingo– ddomingo2016年09月19日 21:36:38 +00:00Commented Sep 19, 2016 at 21:36
1 Answer 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');
}]);