item.link = "www.youtube.com"
{item.about}
This tag is making a call to localhost:3000/www.youtube.com
If you add the "protocol" to link like item.link = "http://www.youtube.com
Will work as expected
Related
I'm currently using Angular for a few weeks for a small project and I wanted to add an anchor in my app.
So normally in order to add an anchor without using any framework, you'd create a block with an ID
<div id="top"> then you'd add an anchor tag <a href="#"> with the href attribute that would be equal to the ID of the block of the page we want to redirect the to.
ex:
<div id="top">...</div>
...
When we click on the link, it scrolls up to the page* to the block we defined the ID with.
*if we add in the CSS of the html or body tag scroll-behavior: smooth;
The issue is that when I add that inside my Angular template, it redirects me to the URL with the name of the ID on the href attribute!
If I take the previous example, here's what would happen:
localhost:4200/login → (click to the link) → localhost:4200/#top
Strangely it treats it as if it was a router link attribute
So I'm wondering how we could add an anchor in Angular
So I found a solution! (thanks to #Benjamin Looi for giving me the link to a relevant post)
So actually Angular has an issue with anchor tags when we want the user to another part of the same page
The solution is to use routerOptions of type extra options in the appRoutingModule and add in some options, here's the code:
const routes: Routes = [...];
const routerOptions: ExtraOptions = {
useHash: false,
anchorScrolling: 'enabled',
onSameUrlNavigation: 'reload' //Must have if you want to be able to use the anchor more than once
};
#NgModule({
imports: [RouterModule.forRoot(routes, routerOptions)],
exports: [RouterModule]
})
export class AppRoutingModule { }
Then in the template, we have to add the anchor of the block we want to redirect the user in the attributes fragment with the name of the ID and routerLink with the page you're in (otherwise it will redirect to "/")
ex:
<a routerLink="/login" fragment="top"></a>
Now it will successfully redirect to the top of the page!
May be this might help
HTML code :
<button (click)="scrollToElement(target)"></button>
<div #target>Your target</div>
Ts code :
scrollToElement($element): void {
console.log($element);
$element.scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"});
}
got it from this
Using HTML anchor link #id in Angular 6
I have a project where I can list distributions. I have a homepage where I have the options to click on the lecture or lecturer. Now I want that when I am on the lecturers page that I can click on one anchor tag which redirects me to the target page. However the URL does only add the new slug. I will post the urls and templates. Hope you can help me, Thanks in advance.
urls.py
app_name='distribution'
urlpatterns=[
path('',views.Index.as_view(),name='home'),
path('<slug:slug>/',views.LecturerDistribution.as_view(),name='lecturer_distribution'),
path('dersler/<slug:slug>/',views.LectureDistribution.as_view(),name='lecture_distribution'),
]
this my part in the lecture code template
<p style="text-align:center;"><a style="text-decoration:none" href="{% url 'distribution:lecture_distribution' slug=i.lecturer.slug%}">{{i.lecturer}}</a> | {{i.semester}}</p>
and here is my cbv for the lecture_distribution
class LectureDistribution(generic.DetailView):
model=Lecture
template_name='lecture.html'
def get_success_url(self):
return reverse('lecture_distribution', kwargs={'slug': self.object.slug})
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context ['distribution_'] = Distribution.objects.filter(lecture=self.object).order_by('-created_on')
return context
my url when I am clicking on the anchor tag is this:
http://127.0.0.1:8000/dagilimlar/dersler/mehmet-cem-guclu/
But it should
http://127.0.0.1:8000/dagilimlar/mehmet-cem-guclu/
as you see the "dersler" field is there which should not it is only for the lectures.
I tried to keep my jinja code in CKEditor as it was after I toggle the view between code view and WYSIWYG view.
And I could get this result by adding below line in my config.js file
CKEDITOR.config.protectedSource.push(/\r|\n/g);
CKEDITOR.config.autoParagraph = false;
However, it does not work well for HTML code. For instance, if jinja code and html mixed together like this:
{% if name=='bob' %}
{{'hello bob'}}
{%else%}
{{ 'hello ' + name }}
{% endif %}
<p>Hello visitor</p>
Here is Demo on Fiddle JS
After this, when I change from code view to wyiwyg view in CKEditor, the HTML code just increase by one new line, and another new line for another toggle view as shown below:
I can't find what is wrong with HTML code, I just what to format jinja code only, how can I fix it? Thanks
Write these additional lines under your code
$("body").on("click", ".cke_button__source", ()=>{
// if(CKEDITOR.instances.editor1.mode==="source"){
let vtk = CKEDITOR.instances.editor1.getData();
// vtk = vtk.replace(/\n<p>/gm, "<p>");
vtk = vtk.replace(/^\s*[\r\n]/gm, "");
$(".cke_source").val(vtk)
// }
})
Here is jsFiddle
I had a link which will get the value of input(text) if not empty and append it to href value. Is there a way to accomplish it?. Heres my code. Thanks in advance.
<a id= "lnk_audio_devices" href="{{route('search.products', ['category' => 'audio_devices',
#if(txt_product.value != '')
'products' => txt_product.value
#endif
])}}" >Audio Devices</a>
First of all, you might want to try a workaround with a form, that is the usual way things like these are done, leading to an url like this foobar.com/foo/bar?yourinput=whatyoutyped. Instead of the button being a link, it nom submits the form.
If you want to keep your laravel routing the same. You will need javascript to append the text value to the link when the button is clicked.
function navigate(link, inputid){
var url = link.href + "/" + document.getElementById(inputid).value;
//window.location.href = url; //navigates to the given url, disabled for demo
alert(url);
}
click me
<input type="text" id="myText">
If type=1, then I want the url to use the variable {{vm.firstPath}}.
For anything else it should use {{vm.secondPath}}.
Is this doable using a ternary?
When I tried doing this it is not recognised:
{{type==1? {{vm.name}} : {{vm.name}}}}
You should use ng-href istead of href for this purpose.
<a ng-href="type == 1 ? 'http://www.google.com' : 'http://www.facebook.com'">Link</a>
var app = angular.module('foo', [])
app.controller('main', function($scope){
$scope.type = 1;
})
JsFiddle : http://jsfiddle.net/nikdtu/b910258t/
you can use ng-if directive. try like this:
<a ng-if="type==1" ng-href="{{vm.firstPath}}">{{vm.name}}</a>
<a ng-if="type !=1" ng-href="{{vm.secondPath}}">{{vm.name}}</a>
You need to change code like this-
{{vm.name}}
Or-
{{vm.name}}
{{vm.name}}