javascript - AngularJS : undefined is not a function from factory -
I have many functions inside my factory and I will save myself with a button click using ng-click. The GetCharacters function works fine only In advance for repost, sorry i have gone to many different instances and can not solve my special issue with them when i log in xmlservice I can see, but I'm not sure why it will not be called. I was trying to return a post to save a php file, but I want to see this string string Turned on to turn what was my problem
Thanks for any help.
(function () {var app = angular module ('field', []); app.factory ('xmlservice', function ($ http) {var factory = {}; Factory .getCharacter = function getCharacter () {return $ http.get ('xml / characterTemplate.xml');} factory; saveCharacter = function saveCharacter () {return "hello"; // return $ http.post ('php / Crud.php ');}; return factory;}); app.controller (' FighterController ', [' $ scope ',' xmlService ', function ($ scope), XmlService) {this.fighterList = fighterList; $ scope .saveFighter = function saveFighter () {console.log (xmlService); xmlService.saveCharacter.success (function) {console.log (data);})}} function loadfighters () {xmlService.getCharacter (). The car (Data) {var x2js = new X2JS (); var characters for list = x2js.xml_str2json (var i = 0; i & lt; letters l ist.characters.character.length; I ++) { Var currentFighter = Character Listers. Charter Charterator [i]; fighterList.push (currentFighter);} $ Scope.FighterController = Characters;});} Loadfighters (); }]; Var Fighter List = []; }) (); I had other questions while writing my first Kangaroo app, what code means:
$ scope.FighterController = lettersList; Do I have permission to use the data given in view? Do I have to reset the scope of my defense to the phater function to work my button?
Am I setting up the dependency for my app.controller correctly, and is it dependency injection?
Thank you all, and any comments regarding the installation of my code are quite commendable!
Did not you actually explained what did you do to fix this issue If I did, I would explain it.
Here, you are trying to call xmlService.saveCharacter.success () :
xmlService.saveCharacter.success (function (Data) {console.log (data);}); but xmlService.saveCharacter is a function. There is no success in property; Success is undefined, it gives you the error you are seeing
You call xmlService.saveCharacter () :
xmlService.saveCharacter () is required. Success (work) {console.log (data);}); But this is still a problem because saveCharacter () returns the function string "hello" . There is no success property in this string even then success is undefined , hence it causes the same error.
To fix that error, you just have to remove "Hello"; and delete the code you commented on:
factory.saveCharacter = function saveCharacter () {return $ http.post ('php / crud.php'); }; Correcting both of those problems should solve your problem.
Comments
Post a Comment