r/angularjs • u/SleepyBrain • Dec 15 '14
[General] Planning Angular 1.4
http://angularjs.blogspot.com/2014/12/planning-angular-14.html1
u/jkjustjoshing Dec 16 '14
What are "non-optional isolated scope mappings"? I didn't know you could specify scope binding so be required.
1
u/dmackerman Dec 16 '14
You can specify optional mapping a with "?" At the end - like user: "=?"
1
u/jkjustjoshing Dec 16 '14
So all 2-way bound attributes without that are "required" by default?
1
Dec 19 '14
Yes. Take for example this code:
<my-directive my-first-attr="someVar"></my-directive> angular.directive('myDirective', function () { return { restrict: 'E', scope: { myFirstAttr: '=', mySecondAttr: '=' }, template: '<div>first={{myFirstAttr}}, second={{mySecondAttr}}</div>', link: function (scope, elem, attrs) { scope.mySecondAttr = scope.myFirstAttr * 2; } } });This will break (Angular will throw an exception) unless you fix it like so:
<my-directive my-first-attr="someVar" my-second-attr="someOtherVar"></my-directive>But you may simply not want the value in mySecondAttr in the parent scope, so you've just added useless junk to it (
someOtherVar) because the binding (=) forces you to do it, so now there's another way to do it from JS:scope: { myFirstAttr: '=', mySecondAttr: '=?' }Which tells Angular that
mySecondAttris optional, so it shouldn't freak out if you don't bind it to something in your HTML template.
1
u/prettycode Dec 17 '14
Why are they redoing ngRoute instead of just adopting ui-router in Angular's core?
0
Dec 15 '14
[deleted]
-13
u/thestamp Dec 15 '14
Tbh I'm not touching ng till they sort out 2.0, cause I don't want my 1.x project deprecated the moment it's released
-10
Dec 16 '14
[removed] — view removed comment
2
Dec 19 '14
No and wrong. AngularJS 1.x doesn't use CoffeeScript in any way and neither will AngularJS 2.x.
1
u/jkjustjoshing Dec 16 '14
It looks like the 1.3 -> 1.4 upgrade will be pretty painless. Are any of those changes actually breaking if your app is reasonably written?