Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Brad Wertman
@bmwertman
In my view I have a week view calendar. When the user swipes left or right they see the dates for the previous or next week. The function feeding those dates is where I use $scope.$emit to push those from CalendarController to ManageCtrl. I need to query my database to check availability of some combination of two resources that the user can select for each of the seven dates returned and update the view to show whether both resources can be scheduled for the required time on those days.
Mike Haas
@mikehaas763
So with what you've got so far get the dates from the event. You can take those dates and pass it to another function or method that you call from the event handler.
Brad Wertman
@bmwertman
Thanks for your help @mikehaas763
Darrin Dickey
@darrindickey

I've got a directive that renders a Google Map. Inside of that directive, I'm trying to use the click function to pass a value to a controller. Ultimately, I want to replace the information inside of a div. In my directive, under Scope, I have: changed: '='.

In my HTML, I have :

<map-list>changed='updateMap(locationId)')</map-list>

In my Controller, I have:
$scope.updateMap = function() {
console.log('$scope.locationId');
};

I can't figure out how to pass locationId from the directive.

Jared
@jareddr
@darrindickey something looks funny with your html there, but if i'm reading it right, locationId will be passed into the updateMap function, would look like this $scope.udpateMap = function(locationId) { console.log(locationId) };
```$scope.updateMap = function(locationId) {
haha oh man i'm not good at gitter chat yet
Darrin Dickey
@darrindickey
It may be from me converting it on the fly from Jade.
But how do I pass locationId out of the directive?
Jared
@jareddr
it depends on where you’re trying to send it to
Darrin Dickey
@darrindickey
I tried scope.changed({ locationId: placeId }), but then I get "changed is not a function"
I want to send it to the controller.
Actually, ultimately I want to send it to the view.
Jared
@jareddr
ya i see, so you’ll define the updateMap function in your controller
and then you’ll send a map id intot your map directive
sorry i feel like i’m not being super helpful, i can’t totally see what your code is trying to do
Darrin Dickey
@darrindickey
In the directive, there is data that includes placeId (unique to each location).
I loaded that into the locationsId variable. And I'm trying to pass it to the controller.
I was using the scope changed: '=' to do two-way binding on the data.
Jared
@jareddr
then i think your html should look more like this
Darrin Dickey
@darrindickey
Was passing through the directive element in the view via changed='updateMap(locationId)'
Jared
@jareddr
<map-list changed=‘locationId’></map-list>
Darrin Dickey
@darrindickey
But that won't call the updateMap function in the controller.
Sorry, I think I'm being confusing. Let me try what you suggest and see what I get.
Jared
@jareddr
correct, so you want something in the directive to call a function in the controller i see
so yeah in your controller define an update map function
this goes in your controller: scope.updateMap = function(locationId) { console.log(locationId) }
then in your html do
<map-list updateMapFunction=‘updateMap’></maplist>
then in your directive you would do
scope: { updateMapFunction = ‘&’ }
then somewhere in your directive you’ll have to call that function you pass in
a button in your maplist could have <button ng-click=“updateMapFunction(1)”>
i haven’t tested that, so i’m not sure if it works, but its in the right direction
Darrin Dickey
@darrindickey
I'll give it a shot. Thanks!
Darrin Dickey
@darrindickey
Tried it, but it still doesn't pass locationId out of the directive.
Jared
@jareddr
your goal should be first just to get that updateMap function in the controller being called
if you can get it called in any form, passing the locationId should be easy
a plunkr is worth a thousand chats
Darrin Dickey
@darrindickey
I'll look at the Plunkr now. I can call the controller function on click. I just can't pass the value from the directive.
Jared
@jareddr
i see
Jared
@jareddr
interesting, yeah I’m stumped when i try to call a function from the parent controller with a parameter. You can change the value directly in the controller with a two-way binding variable, but i’m not sure how to do that with a function
Darrin Dickey
@darrindickey
Is it possible to pass a value from one directive to another?
geoguide
@geoguide
I have a beginner question. If someone logs in I want to show a logout button (or the navigation in general). I figured I’d just change an app variable and then do an ng-show={{loggedIn}} and so I set app.value(‘loggedIn’,true); but it’s not working. What’s the right way to do this? Do have to make a MenuCtrl and then set something in that controller from LoginCtrl? Or do I need to make an AuthenticatedAreaCtrl to wrap around everything? I’m getting kind of lost.
Nelo Mitranim
@Mitranim
@geoguide The typical solution is to have an authentication service that would encapsulate this information
module.value creates a constant, more or less. You don't want to use this for dynamic information
Srinivasan
@kksrini89
I have been doing with ngRoute. I've SPA which having 2 tabs clicking on each tab we show partial as html, but I'm experiencing issue while navigating from one tab to another tab when use like below.
angular.module('sam',['ngRoute']).config(function($routeProvider){ $routeProvider.when('/main/customer',{ templateUrl:"customer.html", controller:"customerController" }) .when('/main/client',{ templateUrl:"client.html", controller:"clientController" }); });
the above line kept it as separate file called app.js, Here I use ASP.NET MVC as backend, so from index.cshtml I did like below
<a href="/main/customer">Customer</a> <a href="/main/client">Client</a>
I am experiencing an issue with above coding. But in angular ngRoute the second / looks for routeParams???that's why I'm getting error??
Can anyone help me in this.
Nelo Mitranim
@Mitranim
@kksrini89 suggest using markdown formatting to make your code more readable. Surround code blocks with triple backticks
Could you please clarify the routeparams issue? It's unclear what your problem is