I just now started learning on AngularJS from w3schools. I am trying to practice examples what ever they have mentioned in the tutorials. Every thing works fine but when i c
I just modified your js fiddle. Please check the fiddle example
function personController($scope) {
$scope.firstName= "John";
$scope.lastName= "Doe";
}
There was no issue with your code except JS fiddle settings from onLoad to No wrap - in head
Same problrm may be if you will try to nest ngApp into anothe ngApp.
The documentation says:
AngularJS applications cannot be nested within each other.
by adding np-app="myApp"
in any tag of html like <html ng-app = "myApp">
my code works fine.
You have to input function as a parameter inside module
var app = angular.module('app',[]);
app.controller('personController',function($scope){
$scope.firstName = 'John';
$scope.lastName = 'Smith';
});
You need to create an application module, and then add a controller to it. In angular it is all about dependencies. Secondly you need an app-name. The base tutorial is on their main page: https://docs.angularjs.org/tutorial/step_00 I started with it, and it worked fine with me. Just do all steps starting from step 1.
It is a new approach. We cannot use controllers without a module no more. Have a look at this. Just add a module and append the controller then you will have no problem.