ng-switch我使用时无法正常工作ng-switch-when-separator.当我选择设置时,开关指向默认div
angular.module("myModule", [])
.controller("myController", function ($scope) {
$scope.items = ['settings', 'home', 'options', 'other'];
$scope.opt = $scope.items[0];
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myModule">
<div ng-controller="myController">
<select ng-model="opt" ng-options="item for item in items">
</select>
<code>selection={{opt}}</code>
<hr />
<div class="animate-switch-container"
ng-switch on="opt">
<div class="animate-switch" ng-switch-when="settings|options" ng-switch-when-separator="|">Settings Div</div>
<div class="animate-switch" ng-switch-when="home">Home Span</div>
<div class="animate-switch" ng-switch-default>default</div>
</div>
</div>
</body>Run Code Online (Sandbox Code Playgroud)
我正在将角度模板插入元素.考虑以下示例,
<p>
<c ng-controller="ctrl">
...
</c>
</p>Run Code Online (Sandbox Code Playgroud)
如果我从javascript中删除c.会有什么副作用?(范围泄漏)如何避免这种情况?
我用过这个,
function render() {
var lastScope = angular.element('c').scope();
if(lastScope) {
lastScope.$destroy();
}
$('c').remove();
getTemplate(context + '/c.html', function(template) {
if (template) {
angular.element(document).injector().invoke(['$compile', '$rootScope', function($compile, $rootScope) {
$('p').append($compile(template)($rootScope));
$rootScope.$apply();
}]);
}
});
}Run Code Online (Sandbox Code Playgroud)
当我点击标签渲染功能时,每次都会调用.还有其他的消化吗?