Leaflet angular error not render properly - angularjs

I am trying to implement a simple leaflet map in my angular test page. I am having the problem you see in the photo attached.
My code is the code in this example:
http://jsfiddle.net/tombatossals/4PhzC/
I have some other things in my page as for example bootstrap libraries to draw some lists and jquery lib. Also, I import ngroutes and socket components . And I am painting the map webpage inside this directive:
<div ng-view></div>
I don't know why inthe example it works and in mine, it doesn't render fine.

Related

ReactJS, JSX and <script>

I'm new to ReactJS and have been trying to figure out the best approach to setting up the front end. I am trying to use a bootstrap template (https://colorlib.com/polygon/gentelella/index.html). I know JSX and HTML are different but are also very similar. When I try and use a snippet of HTML from the bootstrap template as JSX, the styling will appear correctly in the browser, but none of the buttons or graphs work. I imagine this happens because JSX is different from HTML and the rendered version in the browser does not respond to the browser JS. Is there any way around this? Do I have to rebuild all the functionality that comes with the template in a component?

initialize onsenui after document loaded

i´m trying to initialize onsenui after some js files are loaded, but then
ons.bootstrap() is causing the errors.
when i´m using a sample from onsenui everything is working quite good, but in my
project, i have to load the js files dynamically and synchronously
and then ons.bootstrap(); give me the this error
"'AppController' is not a function, got undefined"
if same js libs in same order are declared in html doc with script tags everything is working good.
i´ve found that if the scripts are loading through normal script tags and then i´m waiting till html document is fully loaded and then call ons.bootstrap() through developer tools i got same error.
so the question is how to initlaize onsen ui after document is loaded?
Hope someone can help, I´m not very familiar with angularJS/OnsenUi... first project
thanks
I have create 2 samples to demonstrate my problem.
working like onsenui samples.
jbBgmd http://codepen.io/anon/pen/jbBgmd
not working like in my case.
BoWXdP http://codepen.io/anon/pen/BoWXdP
any idea?
You are trying to load Onsen after the elements have been rendered, that's why it gave an error. You should always execute Onsen before the components are rendered.
If you want to execute some code after the DOM has been loaded, you should use ons.ready() function, you can take a look at it in the official documentation.
Here you can find the fixed and working CodePen: http://codepen.io/andipavllo/pen/ZbKzRy
Here is the edited JS:
ons.bootstrap().controller("appController", function ()
{
ons.ready(function(){
console.log("works")
})
});
Hope it helps!

How to use some ngActivityIndicator on page?

I use Angular JS library to display preloader during is loaded content from AJAX response.
In tutorial tells about using some preloaders on page based on $scope model.
But it does not work for me:
<div ng-show="myLoadingConditional" ng-activity-indicator skip-ng-show="yes"></div>
Can you share a right way using?

Tabs and Carousel in Angular JS

I want to implement tabs and inside the tabs route to a carousel.Can anybody provide me the code sample as I am new to Angular JS and have issues implementing routing inside tabs in Angular JS.Here bootstrap can also be used in Angular JS.
ng-view is not good for you maybe as you can have only 1.
try to take a look at ui-view in angularUI project to enable multiple views with sub views.
as for carousel and tabs, you got implementation for that with angularUI/bootstrap/jqueryUI so no need to implement by yourself.

AngularJS: How to nest applications within an angular app

i've been working on a project that is more like a framework, and has several apps / modules you can install. See it like a basic appstore or google.play store. It's sort of an intranet application, and all modules can be added to your useraccount.
the framework is already in development, but i'm wrapping my head around the applications/modules idea now. (link to a proof of concept in development, can be found here)
an application should be somewhat standalone, and not able to suddenly include scripts from the framework, This is perfectly possible by structuring them in separate modules like so:
angular.module('myApp', []);
however, an app can have templates, scripts, css and it can run on a separate server, so I'm kind of looking for the best way to fetch the script(s) and cssfile(s) and dynamically load them into the app when the user starts the app in from within the framework.
currently I'm structuring apps as if they have a main template for example www.framework.com/apps/myapp/views/app.html, for the sake of simplicity i bundle scripts into 1 script file per application, so there is also a www.framework.com/apps/myapp/script.js to be included.
The framework contains a template that loads the apps, and an appController. The template contains this piece:
<div data-ng-controller="AppController" data-ng-include="app.appTemplate">
<div>loading...</div>
</div>
this basically binds to the $scope.app.appTemplate which is updated when all scripts are loaded, so first it shows a loading template, later after scripts are included in the page it updates the app.appTemplate to the above mentioned main template of an application.
while loading the first index template works, this template is currently loaded with the AppController from the framework, so it is using the $scope of the framework and not it's own script.
I still have to somehow start the app's own angular module, and let it on it's own without running anything in the framework to 'make it work'
I'm still figuring out how to best load the dependent javascript files (will probably use requrejs or other dependency loader) but I have currently no clue how to 'boot' the app without working from within the framework's AppController
EDIT
I created a small demo project to show the problems at hand, full code is visible at git-hub at the moment this project does a few things hard coded, the idea would be that I make those less hard coded when I get the proof of concept right, now it's all about loading the applications within the framework. if that is possible, I can think of where to get the URL's and application names from ...
You can't bootstrap a module inside another bootstrapped module. Bootstrapping compiles the view and binds a rootScope to it, traversing it's way through the DOM and setting up scope bindings and executing directive linking functions all the way through. If you do that twice, you're going to run into problems.
You're probably going to have to rethink your architecture. I think perhaps the word "module" or "app" as it pertains to Angular is a misnomer and is leading you down the wrong path.
Each "user installed app" in your application should probably really be controlled by a controller in your app module, or registered to a module referenced by your app module. So you wouldn't be "starting up multiple apps", you'd really just be starting one, referencing the other modules, then using Controllers from those modules to control parts of your view on the screen.
What you'd do is when a new "widget" was installed, you're register it's module file (.js) with the system, which would contain a controller named WidgetCtrl, then when your page loaded, you'd reference the widget's module on your app module. From there it should be available for dynamic assignment to elements using ng-controller and/or ng-include.
I hope that makes sense.
Contrary to currently accepted answer, It is actually possible.
I was working on a similar problem and suggested answer was not acceptable in my case. I had previously written pages with multiple applications but it was years ago and apps were independent of each other. There are two things to do basically:
Tell main application to ignore a child element.
Bootstrap the child element.
There is an ng-non-bindable attribute which simply tells AngularJS to ignore the element. This handles our first problem.
However when you try to bootstrap the child element; AngularJS will throw an error, telling you that it is already bootstrapped (at least to me, version 1.2.13). Following trick does the job:
<div ng-non-bindable data-$injector="">
<div id="bootstrap-me">
<script src="/path/to/app.js"></script>
<div ng-include="'/path/to/app.html'"/>
</div>
</div>
This solution is not perfect. Ideally, ng-non-bindable attribute can add required data-$injector attribute to element. I am going to make a feature and hopefully a pull request to AngularJS.
I did not have the chance to make a pull request. Apparently and expectedly I should say, some internals have changed but ng-non-bindable is still working at version 1.3.13 using Ventzy Kunev's demo code (thanks again, see link below).
well if each sub-app is in its own module, you can just use angular.bootstrap to load that module dynamically. when the url for a specific app loads, you can fetch the necessary script(s), then when the promise resolves, you can do something along the lines of:
// grab a reference to the element where you'll be loading the sub-app
var subapp = document.getElementById('subapp-id');
// assuming the script you get back contains an angular module declaration named
// 'subapp', manually start the sub-app
angular.bootstrap(angular.element(subapp), ['subapp']);
hope this helps
Similar to UnicodeSnowman's answer above, another potential solution that appears to be working for my needs (I built a live Angular editor on a documentation site) is to manually handle the bootstrap process by having a <div id="demos"> that is separate from the main <div id="myApp">.
This article was very helpful to get it working correctly.
General Process
Create your main app (I chose to manually bootstrap, but you may be able to use ng-app for this part)
Create a new HTML structure/app (in my case the demo app):
Append it to the demos div with a custom id: someCoolDemoContainer
Boostrap the newly created app
Move it back into the original app (for layout/positioning purposes)
Code Example (not tested; just shows basic process)
<div id="myApp">
<h1>Demo</h1>
<p>Click the button below to checkout the cool demo!</p>
<button ng-click="showDemo()">Show Demo</button>
<div class='insertion-point'></div>
</div>
<div id="demos">
</div>
<script type="text/javascript">
/*
* Init/bootstrap our main app
*/
var appContainer = document.getElementById('myApp');
angular.module('myApp', ['myDependency']);
angular.bootstrap(appContainer, ['myApp']);
// Do lots of other things like adding controllers/models/etc.
/*
* Init/bootstrap our demo app when the user clicks a button
*/
function showDemo() {
// Append our demo code
$('#demos').append('<div id="someCoolDemoContainer">Angular app code goes here</div>');
// Bootstrap the new app
var demoContainer = document.getElementById('someCoolDemoContainer');
angular.module('someCoolDemo', ['myDependency']);
angular.module('someCoolDemo').controller('myController', function() { ... });
angular.bootstrap(demoContainer, ['someCoolDemo']);
// Re-insert it back into the DOM where you want it
$('#myApp').find('.insertion-point').append($('#someCoolDemoContainer'));
}
</script>
I know this is quite old now but I was looking for a way to embed an AngularJS app within an Angular app and used the answers from this post to do just that so I thought I'd post up the plunker here for anyone else looking for a similar solution.
There were two ways that I found to do it, both used manual bootstrapping of the angularjs app within the ngOnInit of an Angular component:
ngOnInit(): void {
// manually bootstrap the angularjs app
angular.bootstrap(document.getElementById('ngListApp'), ['list-app']);
}
Either set the ngNonBindable attribute on the element that will be bootstrapped:
<div ngNonBindable #insert>
<!-- can insert the angular js template directly here, inside non-bindable element -->
<div id="ngListApp" ng-controller="ListController as list">
<input ng-model="inputValue" />
<ul>
<li ng-repeat="item in items">{{ item }}</li>
</ul>
</div>
</div>
Or inject the angularjs template html into the element in the ngOnInit event handler within an Angular component so that Angular doesn't try to interpret the AngularJS code (especially interpolation of AngularJS properties in the DOM with curly brackets) during compilation.
ngOnInit(): void{
// insert angularjs template html here
this.div.nativeElement.innerHTML = this.htmlTemplate;
// then manually bootstrap the angularjs app
angular.bootstrap(document.getElementById('ngListApp'), ['list-app']);
}
The Plunker is here:
http://plnkr.co/plunks/0qOJ6T8roKQyaSKI

Resources