ng-switch

$apply in setTimeout

谁都会走 提交于 2020-01-17 07:32:05
问题 I konw that $apply used to connect the Javascript context and the AngularJS context. A simple example is below: template: <div>{{someVal}}</div> javascript in controller: setTimeout(function() { scope.$apply(function(){scope.someVal = 123}); }, 1000); We need use $apply in above situation. First Qustion: If I modify javascript above to: setTimeout(function() { scope.someVal = 123; }, 1000); scope.$watch('someVal', function(val) { console.info(someVal); }); No console about someVal modified to

When has ng-switch finished rendering?

有些话、适合烂在心里 提交于 2020-01-06 03:17:06
问题 I'm using ui-router and trying to instantiate a widget that takes as a parameter a DOM element specified by id. This DOM element is in a <div ng-switch> and I want to call the widget constructor when the element is guaranteed to exist. <div ng-switch on="state"> <div ng-switch-when="map"> <div id="map"></div> </div> </div> From the ui-router lifecycle, I understand that I should hook into $viewContentLoaded . This, however, doesn't work - the DOM element within the ng-switch isn't created at

When has ng-switch finished rendering?

独自空忆成欢 提交于 2020-01-06 03:16:11
问题 I'm using ui-router and trying to instantiate a widget that takes as a parameter a DOM element specified by id. This DOM element is in a <div ng-switch> and I want to call the widget constructor when the element is guaranteed to exist. <div ng-switch on="state"> <div ng-switch-when="map"> <div id="map"></div> </div> </div> From the ui-router lifecycle, I understand that I should hook into $viewContentLoaded . This, however, doesn't work - the DOM element within the ng-switch isn't created at

Using html templates in angular's ng-switch

杀马特。学长 韩版系。学妹 提交于 2019-12-30 06:05:48
问题 Im making an 'interactive menu' that moves along with user clicks. Im wondering if there is a way to include html templates in ng-switch, since all the logic is different in each 'switch' - it will result in huge html files. <div class="content" ng-switch on="selection"> <div ng-switch-when="1" > <h1>1</h1> </div> <div ng-switch-when="2"> <h1>2</h1> </div> </div> 回答1: Use ngInclude : <div class="content" ng-switch on="selection"> <div ng-switch-when="1" > <ng-include src="'template1.html'"><

Using html templates in angular's ng-switch

时光总嘲笑我的痴心妄想 提交于 2019-12-30 06:03:44
问题 Im making an 'interactive menu' that moves along with user clicks. Im wondering if there is a way to include html templates in ng-switch, since all the logic is different in each 'switch' - it will result in huge html files. <div class="content" ng-switch on="selection"> <div ng-switch-when="1" > <h1>1</h1> </div> <div ng-switch-when="2"> <h1>2</h1> </div> </div> 回答1: Use ngInclude : <div class="content" ng-switch on="selection"> <div ng-switch-when="1" > <ng-include src="'template1.html'"><

Angular.js ng-switch-when not working with dynamic data?

雨燕双飞 提交于 2019-12-28 05:18:25
问题 I'm trying to get Angular to generate a CSS slider based on my data. I know that the data is there and am able to generate it for the buttons, but the code won't populate the ng-switch-when for some reason. When I inspect the code, I see this twice (which I know to be correct as I only have two items): <div ng-repeat="assignment in assignments" ng-animate="'animate'" class="ng-scope"> <!-- ngSwitchWhen: {{assignment.id}} --> </div> My actual code: <div ng-init="thisAssignment='one'"> <div

How to use ngSwitch on datatype in angular?

醉酒当歌 提交于 2019-12-24 05:44:08
问题 I was working in angular2 and was curious to know whether I could use ngSwitch to load <div> tag when variable is of certain datatype.i.e. something like this: <div [ng-switch]="value"> <p *ng-switch-when="isObject(value)">This is Object</p> <p *ng-switch-when="isArray(value)">This is Array</p> <p *ng-switch-when="isBoolean(value)">This is Boolean</p> <p *ng-switch-when="isNumber(value)">This is Number</p> <p *ng-switch-default>This is Simple Text !</p> </div> is this possible to load the div

ngSwitchCase in angular 2 instead of ngSwitchWhen

心已入冬 提交于 2019-12-23 22:09:09
问题 I was using ngSwitchWhen & now I want to use ngSwitchCase, I referred to the syntax here https://angular.io/docs/ts/latest/api/common/index/NgSwitch-directive.html & did the same in my application. There aren't any errors but it isn't working fine either. Somehow the plunker available in the above link for the example provided uses ngSwitchWhen. Here's my sub.component.ts: @Component({ selector: 'subjects', templateUrl: 'app/subjects.component.html' , styleUrls: ['app/app.component.css'],