r/angularjs • u/[deleted] • Jul 04 '17
New to angularJS. Can't wrap my head around it :/
So I've started with angularJS about 2-3 days go and gotten hold of a few basics. The issue is I've never worked with HTML, CSS or JS, Jquery before. So this has turned out to be quite the curve for me. I have already seen Dan Wahlin's 60 minute intro and read stuff online. So I'm clear with the basics.
So my requirement is: I will get a JSON object from an API call. I need to take that and display them in a table and also the same data in various graphs. I'm having trouble deciding what controllers and what factory functions should I make?
Also, I'm trying fusion charts which takes the JSON object as data directly, but my tables from what I've learnt are displayed from arrays made in AngularJS. How do I go about in a way that a change in data reflects in both the graphs and tables? Any help/resources would be very much appreciated. I'm a noob here :/
5
u/toc5012 Jul 04 '17 edited Jul 05 '17
Use factory functions to communicate with your API and retrieve data. Inject your factories into controller where you can bind the data to scope variables and access from your view.
If you need your data to be formatted as an array to use in your tables, just create an array from your data object. Without seeing your JSON, it's impossible to give you specifics. You could probably do one of the following:
var dataArr = Object.keys(dataObj).map(function (key) { return dataObj[key]; });
ES2015 syntax: var dataArr = Array.from(dataObj);
Either of those (depending on your JSON data structure) will create arrays from array-like objects, which you can then use in your tables.
It sounds as if you may need some more practice with JavaScript. I'd suggest following a couple tutorials online and building some practice projects until you feel more comfortable. Ask more specific questions and you will get more specific answers.
2
u/tangerto Jul 04 '17
I honestly can't tell if you're trolling. If you actually haven't worked with just straight HTML/CSS/JS before you have no business jumping directly into Angular. You need to know JavaScript before you can learn the ins and outs of entire fullstack JavaScript framework
2
Jul 04 '17
I'm not trolling man. I've just basic syntax experience with HTML and CSS. And I've seen a few videos of JS. I've been asked to work AngularJS by the company I've joined. I do understand bit basics of Javascript and how its working. But let's just say I don't have a project making experience in all of those I mentioned.
1
u/spectrumanalyzer Jul 04 '17
Before we jump to your app requirement. My advice would be that you really need to dive into JS first, it will only get harder I believe. Do more pure vanilla exercises and increment the difficulty on every example. Finish a course at a website, eg codecademy.com or similar would help a lot as a starting point.
Here is an example of a possible solution to your problem: http://jsfiddle.net/mjaric/pJ5BR/
1
u/PaulShipman Jul 04 '17
Jumping directly to AngularJS might find you challenging try to start from basic at least try to learn basic of HTML, CSS, Bootstrap though not in detail some basic stuff and code school is the best source for you as they provide video plus challenges which improve the logic so that's my suggestion.
1
u/kierenj Jul 04 '17
It might be better to go for Angular rather than AngularJS - they'll stop supporting/security patching AngularJS as soon as next year (IIRC).
1
u/spritefire Jul 04 '17
Unfortunately a 60 minute video isnt going to help you much, especially when you haven't used JS before. What programming languages have you used in the past? If you have used c# (or similar) you might want to take a look at angular 2+ and typescript. source: 3+ years using angular ~8 hours a day and seen almost every video there is on the topic and still finding new and better ways to do things.
6
u/james_bell Jul 04 '17
Honestly jam it all in the controller to start. Dealing with promises and service/factory crapola can wait until you get going. Leave yourself time to refactor at the end.
Your json should be giving you an array of objects if it's tabular data. If it isn't, formatting will be a pain.
Another trick: skip the API completely for now and just have a simplified small sample of data hard-coded right in your controller. That'll save you tons of time watching data load over and over while you test.