Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
leftist heap
Feb 28, 2013

Fun Shoe

Lumpy posted:

So I'm going to start messing about with one of these MV* things for fun, and I've looked at sample code / tutorials for a few, and Ember makes a lot more intuitive sense to me, but all the chit-chat from all the skinny jeans kids on the internet seems to be about Angular. Is this just because of :google: and it's just the flavor of the month, or is Angular on it's way to becoming the jQuery of client side app frameworks?

A little bit of both? Angular is a super powerful framework, but it's not without its warts and issues.

After taking a look at EmberJS over the past couple of days I'm intrigued enough that I'd like to know more. I have a set of issues with Angular that don't look like they're going away anytime soon, but look like they're somewhat solved in Ember.

Adbot
ADBOT LOVES YOU

leftist heap
Feb 28, 2013

Fun Shoe
an skeleton everything you're doing just sounds... wrong. Anyway. AngularJS allows the arbitrary nesting of forms via the ng-form tag. Sub-forms will propagate their validity up to their parent forms. I made you a jsFiddle and everything because I'm bored.

http://jsfiddle.net/jK72r/

The validation of subForm propagates up to myForm.

leftist heap
Feb 28, 2013

Fun Shoe
What about it didn't work? Works fine in the jsFiddle. Maybe there is some scope wackiness on the go with the ngGrid stuff? I've never used ngGrid before. Do you have a top level form that contains everything?

leftist heap
Feb 28, 2013

Fun Shoe

excidium posted:

So I've wrote an app that I'm going to publish and it works fine and dandy. This is the first time I've really used AngularJS and wrote a non-trivial JS app. I really want to take my work now and learn from my mistakes to improve my efficiency going forward. I feel like a major sticking point is code repetition. Looking at this snippet, what can I do to improve this code? I have a bunch of different calculations and they are all set up exactly like this. It seems like the favorite stuff should be easy to extract but I'm not sure where to start.

code:
angular.module('CalcApp')
  .controller('XYZController', function ($scope, $route, localStorageService) {
		$scope.equation = {};
		$scope.equation.name = 'XYZ formula';
		$scope.equation.formula = '(a * 1.5) + 8 ± 2';
		$scope.change = function () {
			$scope.equation.outputLow = (($scope.equation.a * 1.5) + 8) - 2;
			$scope.equation.outputHigh = (($scope.equation.a * 1.5) + 8) + 2;
		};
		$scope.isFavorite = localStorageService.get('xyz');
		$scope.addFavorite = function() {
			localStorageService.add('xyz', true);
			$route.reload();
		};
		$scope.removeFavorite = function() {
			localStorageService.remove('xyz');
			$route.reload();
		};
	});

There is nothing all that magical about AngularJS controllers. At our company we use a mixin pattern to separate out common functionality. See here for an example:

http://digital-drive.com/?p=188

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply