I am a newbie for angularjs. I am creating an application where my home page will list the posts. I had thought of using Angularay for binding in two ways for that page alone. I started with a sample page but participated in issues here itself.
My sample page is using the ng-app for this part alone because I do not necessarily need angular to communicate with any other aspect of the page.
& lt; Div ng-app = "posts" & gt; & Lt; Ul class = "post_list" ng-controller = "post controller" & gt; & Lt; Li ng-repeat = "post in posts" & gt; {{Post.title}} {{post.description}} & lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Div & gt; I have an app.js file that contains
var app = angular. Module ('post', []); and
(define a controller in the form of the function (angel, app) {// constructor function}) with a post controller. Js file. Console.log (app); Console.log (angular); App.controller ("PostController", ["$ scope"], function ($ radius) {$ scope.posts = [{"title": "asdf", "description": "description"}, {"title": "Second one", "description": "second description"},];});}) (angular, app); I am getting my home page loaded
Error: The argument is not the "post controller" function. String [googlecdn path] angular.min.js: 16
What am I missing here Please help me because I am totally confused. I'm new to anjular and for javascript.
The problem is in the way that you are announcing your controller. You should show it below:
app.controller ("PostController", ["$ scope", function ($ scope) {$ scope.posts = [{"title": " Asdf "," description ":" description "}, {" title ":" second one "," description ":" second description "},];}]); Please note that the second argument is an array with both a string as a $ scope and elements of the array, it is a proper syntax, - Used to write secure code.
No comments:
Post a Comment