Using ng-non-bindable along with ng-if in Angular Google Maps allows for certain elements or

I recently came across an interesting discussion on the necessity of ng-non-bindable for the <ui-gmap-windows> element in Angular Google Maps. It shed some light on how ng-non-bindable is utilized in the directive.

However, I encountered an issue while attempting to utilize ng-if to selectively display certain icons in my marker infowindows. Unfortunately, ng-if doesn't cooperate well with ng-non-bindable, but removing it breaks the functionality of the info windows.

If anyone has a workaround to make ng-if function effectively in this scenario or offer an alternative solution, I would be greatly thankful.

      <ui-gmap-windows show="show">
            <div ng-non-bindable>{{obj.name}}<br>{{distance}} miles
            <span class="ion-man" ng-if="obj.men"></span>
          <span class="ion-woman" ng-if="obj.women"></span>
            <span class="ion-ios-people" ng-if="obj.people"></span>  
            </div>                     
          </div>
      </ui-gmap-windows>

Answer №1

To make use of the templateUrl and templateParameter attributes on the ui-gmap-windows directive, ensure that the templateUrl refers to the path of the .html template you wish to use, and the templateParameter contains the necessary parameters. You can view the code snippet below for reference. For more details, check out the documentation here.

<ui-gmap-windows  idKey="'name'" show="show" templateUrl="'pathToHtmltemplate.html'" templateParameter="'{name: 'name', distance: 1.3, womens_restroom: true}'">
</ui-gmap-windows>

In the html template, you can easily utilize ng-if without any issues.

Remember to refer to the object passed into templateParameter as a parameter in your html template. For example, the pathToHtmlTemplate.html file would look like this:

<div>
    {{parameter.name}}<br>{{parameter.distance}} miles
    <span ng-if="parameter.womens_restroom" class="ion-woman"></span>
</div>

Answer №2

The main reason for the lack of functionality is due to the fact that the priority of ng-if (600) is lower than that of ng-non-bindable (1000). Additionally, ng-non-bindable has the attribute terminal:true, causing ng-if to not compile because of the terminal nature of ng-non-bindable. One potential solution could be to use ng-switch (1200) directly on the element with ng-non-bindable, as it has a higher priority. However, this may not be suitable if there are multiple conditions that could be true.

Another approach is to create a custom directive, such as my-non-bindable, with a specified configuration of {priority:599, terminal:true}, and then use it in conjunction with ng-if like so:

.directive('gmapTemplate', function() {
return {
priority: 599,
terminal: true
};
});

Then, utilize it with ng-if.

<div gmap-template ng-if="someCond">{{obj.name}}<br>{{distance}} miles

If not, you may need to enclose non-bindable elements within an element with ng-if:

<div ng-if="someCond">
   <span ng-non-bindable>{{obj.name}}<br>{{distance}} miles</span>
</div>

angular.module('app', []).directive('gmapNonBindable', function() {
return {
priority: 599,
terminal: true
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<div ng-app="app" ng-init="test:123; show:false">
Show-->
  <input type="checkbox" ng-model="show" />
  <div gmap-Non-Bindable ng-if="show">{{test}}</div>


</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When using Vimeo's JS API, the player.loadVideo() method will revert the player's settings back to their default options

Using Vimeo's player.js API, I'm setting options on the player to disable the title upon initialization: var options = { id: 59777392, title: false }; var vimPlayer = new Vimeo.Player('myDiv', options); The video player correc ...

The $q.all() function in angular seems to struggle with resolving properly

Having trouble with 3 $http calls in a factory. Creating 4 promises: var promise = $q.defer(), PBdeferred = $q.defer(), Rdeferred = $q.defer(), Pdeferred = $q.defer(); Making the first call to the API: $http.get('/pendingBills').then(fu ...

Managing uncaught exceptions in node.js

While working on my project, I encountered an issue with catching exceptions when opening a connection using mongoose.createConnection. Here's the code snippet causing the problem: var createdDb = mongoose.createConnection(connectionString); createdD ...

Discover how to extract a whole number (and *exclusively* a whole number) using JavaScript

Is it possible to convert a string to a number in a way that only integers produce a valid result? func('17') = 17; func('17.25') = NaN func(' 17') = NaN func('17test') = NaN func('') = NaN func('1e2& ...

Retrieve only ObjectIds that are embedded in an Array using MongoDB's .find() method

I am looking to extract only the ObjectIds from a specific document that is nested within the projects Array. I am working on creating a database where each user will have their own set of projects. Thank you! db.users.find().pretty() { "_id" : Obje ...

Obtain the value of a URL parameter on a webpage without needing to refresh the

I have a list of records on a webpage, each with a unique URL pointing to another page with a parameter in the URL. When any of these records are clicked, I want to display the value of the URL parameter in an alert without reloading the page. <script& ...

Is there a way to verify if a user taps outside a component in react-native?

I have implemented a custom select feature, but I am facing an issue with closing it when clicking outside the select or options. The "button" is essentially a TouchableOpacity, and upon clicking on it, the list of options appears. Currently, I can only cl ...

JavaScript Email Validation

Check out my JavaScript code below: $scope.isValidEmailAddress = function(emailAddress) { // var pattern = new RegExp(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/); var pattern = new RegE ...

There is no assigned value in scope for the shorthand property. You must either declare one or provide an initializer

I'm just starting out with TypeScript. Encountering the error 'No value exists in scope for the shorthand property 'firstName'. Either declare one or provide an initializer.' while using Prisma with Next.js to create a new user in ...

How can I retrieve the height of a hidden image in Internet Explorer?

I am encountering an issue with images that have been set to display:none. I am using javascript (document.getElementById('elem').height) to retrieve the height/width of these images. While this method works in most browsers, IE is reporting th ...

Creating a primary index file as part of the package building process in a node environment

Currently, I have a software package that creates the following directory structure: package_name -- README.md -- package.json ---- /dist ---- /node_modules Unfortunately, this package cannot be used by consumers because it lacks an index.js file in the r ...

Encountering a syntax error with JSON.parse() when using MVC 4 Razor with Jquery Ajax

I am encountering an issue with my MVC 4 application login page. I am attempting to utilize a jQuery ajax request to my login controller to check if the user exists. Here is the snippet of my jQuery code: $(document).ready(function () { $("#btnSub ...

SapUI5: Implementing a toggle functionality to display/hide one list item based on another list item's action

UI5 is a versatile framework with numerous possibilities, but sometimes I find myself struggling to implement ideas that would be easier in traditional HTML. Here's the scenario: I want to create a List with ListItems that display cities like Berlin, ...

The command is not currently carrying out its function

I am attempting to verify whether the "sender" has either of the two specified roles, but for some reason the command is not being executed. There are no errors showing up in the console, it's just that the command doesn't run. const revAmount = ...

In jQuery, a dropdown selection can be filled with multiple textboxes sharing the same class

I'm experimenting with the idea of using multiple textboxes with the same class filled with different dropdown options that also have the same class. However, I am encountering some issues. When I click on a dropdown option, it changes the value in a ...

Remove an element from an array based on the index provided by the front end

Currently, I am attempting to eliminate a specific item from a PHP array stored in a JSON file. Here is an example of the JSON file structure: { "1.49514754373E+12": { "description": "I don't like it", "fileNames": [ " ...

Issues with arguments not being identified - Discord.js version 14

After discovering that my arguments are no longer being recognized when executing a command, I encountered a strange issue. When args are not included, my console logs undefined, but if args are added, nothing is logged. This is snippet of my command hand ...

Ensure $q.all does not produce an error when one promise is not resolved

While geocoding addresses, there are instances where some fail. My goal is to retrieve the successful results and disregard the failed ones in order to display the coordinates on a map. Currently, using $q.all triggers the errorHandler when one promise i ...

Using Sequelize to send data from the client-side to the server-side

I am currently developing a project for a fictional library database and website interface. I am facing an issue where only 2 out of the 4 new loan form inputs are being passed to the req.body. Even though all items have a name attribute, it seems like onl ...

Leveraging the power of JavaScript and possibly regular expressions to extract numerical values from a

I am attempting to extract a variable number from the text provided in the following example: Buy 5 for € 16.00 each and save 11% Buy 50 for € 15.00 each and save 17% Buy 120 for € 13.00 each and save 28% Buy 1000 for € 10.00 each and save 45% Th ...