javascript - How to write a directive in Angular.js to scrape dom for data -
I am a Angular.js noob and need help with a small problem. The CMS I work with does not have any service; JSON will not produce my only option is to get my data from dom I know it is not ideal and will be different in the whole world but they are not.
I have a device on the page hidden with CSS. There is folk data in the chaotic list. This is my service :)
I believe I need to wrap my jQuery, which is to move the domain for data in a 'instructions', but this is not how it is known. >
Maybe I do not even need jQuery to get this data. Can this type of angular?
var izular app = angular.module ('angular app', []); AngularApp.controller ('PeopleCtrl', ['$ scope', PeopleCtrl function ($ scope) {$ scope.people = []; // Do not want it in controller. Scanning the domain for data / one instruction? ? $ ('.public-data li') each (function () {$ scope.people.push ({name: $ (this) .find ('.name'). Text (), email: $ (this) .find ('.email') .text ()});});}]); There is a plunk:
I created a new plan here Instructions:
Actually, you have to add:
angularApp.directive ('domScrapper', function () {return {restricted: "A", link: Function (scope, element, ether) {scope. लोक = []; $ ('.public-data li'). Each (function () {scope .pipul. ({{$ Name: $ (this) .Find ( '.name') .text (), email: $ (this) .find ('.email') .text ()})}}}}}}}); And then, you should give that element the dom-scrapper attribute Need to add which you set your controller. I have added a console.log to your controller, which tells you that the instructions and controllers share the same scope, because I do not know what you want to do with the data. P>
In your index.html, I've also switched jquery and angular to a lightweight version of angular jQuery Yoga is, unless you have any library before Do not need angular library. Since you need jQuery, it's better to keep it first. You can do this here: Hope it helps.
Comments
Post a Comment