Saturday, 12 August 2017
angularjs - Add a "parent" function to run before all components
Answer
I'm not sure what the term is, but I need to give the same data to all components in my app. Here's the basic structure of my app:
BeforeAngular.js
function DataModel(json){
this.name = json.name || "No name"
}
//// JQuery ////
function getDataModel(name) {
return $.get(baseURL + "data-model/" + name).then(response => {
return new DataModel(response)
})
}
AppSetup.js
var app = angular.module('MyApp', ['ui.router', 'ngResource', ...]);
app.config(function($stateProvider,$httpProvider,$urlRouterProvider,$sceProvider) {
$sceProvider.enabled(false)
// Each of these components need `getDataModel()` - how can I do that once and send it to all of them with Angular
states = [
{
name: 'Interactor',
url: '/interactor',
component: 'interactorcomponent'
},
{
name: "otherwise",
url: "*path",
component: "viewMDLcomponent"
}
];
states.forEach(state => $stateProvider.state(state))
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
}
ViewMDLComp.js
angular.module("MyApp").component("viewMDLcomponent", {
templateUrl: "html/View_MDL.html",
controllerAs: "c",
controller: [..., View_MDL_Controller]
})
function View_MDL_Controller($http,$timeout,$filter,$log,$q,$sce,l,FileSaver,Blob) {
var c = this
$q.when(getAllDataModels().then(r => {
console.log("getAllDataModels");
c.allMisDataModels = r
})
}
So how Can I run something in Angular that compiles before my components, and feeds them the data they need?
Subscribe to:
Post Comments (Atom)
casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV
In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...
-
I'm using Simple HTML DOM to extract data from a HTML document, and I have a couple of issues that I need some help with. On the line th...
-
I've just started to learn CodeIgniter and gotten trouble with example below: My Controller: class Site extends CI_Controller ...
-
I am working with OpenSSL to try and get the SHA512 Hash function to work. When I am writing the code, Visual Studio's intellisense find...
No comments:
Post a Comment