Accessing the same variable in a directive and controller in AngularJS

A few days ago, I was working with this type of structure in AngularJS:

I had a directive, contentTagButtons inside of an Angular controller, which was pretty basic.  I needed to be able to assign a value to a variable in the contentTagButtons directive, but still have access to it in formController. This is where directive scope comes in handy.

In my directive:

 

For my purposes when I set the scope attribute to false, the directive uses its parent scope. This means that $scope.someSharedVar my contentTagButtons directive  would be the same as $scope.someSharedVar in my formController controller.

Shidhin explains directive scoping in more detail in his post here.

Concatenate an array in JavaScript

I’ve been slacking off on the food-related posts lately because of my day job. Then it occurred to me that I started this blog as a general repository of things that interest me, even non-food things. I read a recent article about how productive StackOverflow has made developers because they no longer have to RTFM. I know I have found a lot of value in googling bugs in my code.  In an effort to contribute to the interweb knowledge base, I’m going to try to post a couple of short blogs each week with tips I’ve learned while developing, no matter how elementary they could be.  Who knows, maybe someone else will save some time by stumbling on these posts.

Recently, I’ve been needing to concatenate arrays in JavaScript.  Using the concat() method is tricky because concatenating one array into the other creates a new array instead of altering the original array:

 

The above isn’t exactly what I wanted, so I’ve been doing this instead, which lets me concat an array into the first array, altering the first array:

 

The Humble Baozi is a Must Eat in Shanghai

On this recent trip to China, I was happy to still be able to find street food in Shanghai.  Even in more affluent areas, I could wander down an alley and find delicious, cheap food of questionable cleanliness.

One type of place that’s easy to spot is the baozi (bun) stand, thanks to the stacks of giant steamers.  The good ones have people crowded around them in the morning like this one across the street from where we were staying.

Unless it’s a fancier type place, don’t bother queueing since an older Chinese person is just going to elbow their way in front of you anyway.  Just figure out 1.) what filling you want, 2.) how many you want, and 3.) how much money to hand the vendor before wrangling your way to the front of the steamers.

It’s hard to find good savory baozi in the US because they’re often pre-made or frozen and realistically, nothing will taste as good as a bun that’s still steaming straight from the bamboo steamer.  The buns I got in China were still white and fluffy, but the bread part was less sweet and the filling was more textured.  My favorite is the mei cai rou bao, which is a baozi filled with dried pickled cabbage and ground pork — I ate plenty of those.

I also ate a couple of baozi with a pickled green bean and pork filling. The green beans tasted like chopped up versions of the spicy and sour green beans that often show up as cold appetizers in Chinese restaurants in the US. There was only a sprinkling of pork for flavor, but that was enough. The combination of hot and tangy in the morning may be too much for some, but I’d imagine it’s a great hangover cure.

For the vegans, there’s the ubiquitous xiangu baozi which is filled with usually filled with chopped shiitake, baked tofu, and lightly pickled green vegetables.  Usually, other than a sweet filling, this is the only vegan option.

On one morning, I decided to branch out from my usual stand to a different one across the street that was attached to a larger, more formal restaurant.  It had the same amount of people lining up in front of it, so I thought it would be safe, but it turned out to be a disappointment. The baozi didn’t taste as good and the filling was cold.  This just cements my bias that the smaller baozi stands are more delicious.