I used like this in angularjs before. And now I m moving to Vuejs.
How can it be replaced in Vuejs?
angular.element(document.querySelector('.popup-inner#company-etc')).css('display', 'none');
You can use $refs
<div ref="companyEtc" class="popup-inner" ...
...
this.$refs.companyEtc.style.display = "none"
I would advise to use conditional rendering: https://v2.vuejs.org/v2/guide/conditional.html
You also can find more information about getting element in a component in answers to the question: Vue.js getting an element within a component
Related
I'm fixing a bug on some legacy Angular 1.5 code.
I have a template like this
<div id="container" ng-if="ctrl.show_container">
<div id="child"></div>
</div>
I need to manipulate the div#child. I'm using $element.find() to get the child div. Unfortunately, it seems that code runs before the template/DOM has finished rendering -- due to the conditional rendering on the container, it doesn't find anything. If I remove the ng-if, it's able to find the element as expected.
Is there any way I can execute my DOM manipulation until after all the conditional rendering is done?
Thank you
If simple case you just do:
ctrl.show_container = true;
$timeout(() => $element.find(...))
If that is not enough you'd better add some directive on that #child element.
scope.$watch('$viewContentLoaded', functionToManipulateDom)
I grab content from a CMS via Gatsby. Inside the markup there are placeholders which should be replaced with React elements.
So I get sth like this:
let content = '<span>Hello World [placeholder]!</span>';
and in React I want to change it to sth like this (where the markup for the tooltip comes from a React element):
let content = '<span>Hello World <div class="tooltip">Important warning</div>!</span>';
The final html with the replaced elements should be dumped into the DOM using dangerouslySetInnerHTML.
I tried using react-string-replace:
reactStringReplace(content, '[placeholder]', () => (<Tooltip />));
but it gives me an array containing a mix of strings and React elements that can't be concacenated without breaking the HTML structure.
What would be a good approach to tackle this issue? Or am I wrong using placeholders in the CMS altogether?
i found a really good npm package that provides this functionality and much more: https://interweave.dev/
I am having a problem were I cannot tell jade to render my custom elements of angularjs origin (directives), I want to know if there is any way to escape the tags so maybe at least they will be rendered as they are instead of going for the jade pre-processor, or maybe a way to tell jade to render my custom element somehow.
The current code looks like :
html
head
link(href='/main.css', rel='stylesheet')
script(src='/lib.js')
script(src='/main.js')
title!= "Neuron#l"
meta(charset="utf-8")
link(rel="icon",href="/images/neuronal.png")
body(ng-app="app",ng-view)
"<top:bar></top:bar>"
"<left:bar></left:bar>"
If the problem it's top:bar and left:bar here is the solution:
html
head
link(href='/main.css', rel='stylesheet')
script(src='/lib.js')
script(src='/main.js')
title!= "Neuron#l"
meta(charset="utf-8")
link(rel="icon",href="/images/neuronal.png")
body(ng-app="app",ng-view)
top:bar
left:bar
I know it's pre-release, but does anyone know if it's possible to pass an argument to an Angular 2.0 component
<div *foreach="#city in myObj.cities">
<city-view current="city"></city-view>
</div>
class CityView{
...
}
I have the code above, but I am not sure how to pass a city into the city-view component. Does anyone know the proposed syntax? The above code will loop, but it does not allow me to pass data to the component.
I have tried this in a newer alpha version of Angular 2.0 and the syntax is like this now:
<div *for="#city of myObj.cities" >
<city-view [current]="city"></city-view>
</div>
Here is a full working example of an angular 2.0 template:
http://www.syntaxsuccess.com/viewarticle/recursive-treeview-in-angular-2.0
I have a HTML-Document containing moustache expressions that angular-dart evaluates very well:
</head>
<body ng-cloak>
<ctrlTextElements>
<div id="stage">outside: {{ctrlTextElements.test1('three')}}</div>
</ctrlTextElements>
I want to dynamicaly add some HTML with moustache expression like so:
CtrlTextElements.addTextElement(mousePos.x, mousePos.y);
var div = dom.querySelector('#stage');
HttpRequest.getString("../path/text.html").then((r) {
div.children.add(new Element.html(r, validator: new AllowAllValidator()));
});
The content of the added text.html looks like this:
<div>inside: (not evaluated): {{ctrlTextElements.test1('three')}}</div>
That's the result in the browser:
outside: three
inside: (not evaluated):{{ctrlTextElements.test1('three')}}
How can I reevaluate the moustache expressions inside content that has been applied after the page was loaded?
The problem is that you are mixing jQuery like logic with angular logic here : manipulating the dom 'by hand' is rarely a good solution.
The problem here is that your newly added binding has not been compiled by angularjs = it has not been indexed as a directive that should be watched for and updated when scope changes.
Either you try a more angular way, for example using ng-hide or ng-repeat directive to display your content according to the controllers $scope (or another custom directive), or you try to $compile your newly added directive ( but this is bad ) : https://docs.angularjs.org/api/ng/service/$compile .
Maybe try in your controller :
$scope.$compile( div );
Not sure of the syntax though. Maybe you would need to write
<span ng-bind="..."></span>
instead of
{{ ... }}
to make it work.
#Alexhv is right. Sorry for my previous answer. I assumed it is about Polymer. Was already time for bed.
You can find a code example in my answer to this question: setInnerHtml doesn't evaluate Mustache
The pub package bwu_angular (http://pub.dartlang.org/packages/bwu_angular) contains this code as a Decorator (Directive) named bwu-safe-html