简体   繁体   中英

Creating a simple hello world application using angularjs

I am a java developer with 0 experience in java script. I am trying to learn angular and did tweak some projects to understand bit of angular. But I am definitely making some error in the basics. I am trying to run a hello world program in angular. I have an index.html and a controller in app.js . I am trying to call a function and show Hello {{something}} !! . I am unable to understand where I am going wrong. Please bear with me and clarify my mistake. here is the fiddle .

var myAppModule = angular.module('myModule', []);

var appController = function ($scope) {
   $scope.greeting = returnGreeting;
};

var returnGreeting = function($scope){
    return 'Hi '+$scope.name+ ' !!';
}
myAppModule.controller('appController', ['$scope',appController]);

You didn't initialize ng-app="" so your app is not working, also you didn't define $scope.name so it returns undefined

Here is the working link: http://jsfiddle.net/QUB4f/8/

Spend time learning JavaScript, without the knowledge of language using complex framework is not a good idea

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM