javascript - ng-option with static link option -


To add a static option that shows links to other pages using the ng-options.

  & lt; Class = "form-control" ng-model = "person" ng-option = "person name for person in person" & gt; & Lt; / Select & gt;  

I am using selection element with NG-option with the predefined list of individuals, where the person is the object. I tried to use ng-repeat instead but this method Does not work:

  & lt; Select ng-model = "person" onChange = "window.location.href = this.value" & gt; & Lt; Option value = "# / home" & gt; Anywhere & lt; / Options & gt; & Lt; Option value = "# / current" ng-repeat = "person in person" & gt; {{Person.name}} & lt; / Options & gt; & Lt; / Select & gt;  

Varibale $ Opportunity. The value gets the value "# / current" works in this case, but the ng-model fails. The variable $ scope.person should represent the selected person.

What do I expect that $ scope.person has selected the price, unless the user chooses to "anywhere", in which case it should be redirected to another page.

"# / home" and "# / present" represent url space "# / home" is a home page and "# / current" is a current page. On-change event redirects the user to the home page or reloads the current page.

So when users select "anywhere" they should be redirected to the home page. The user's page will not be changed for any other option.

First you should not mix native js and angulares unless you really know what Used to be.

Use ng-change instead of ONG and check the value if it is the value of 'anywhere' If this is the route, otherwise there is nothing in your view, you can redirect it in both the situations. Are there.

  & lt; Ng-model Select = "person" ng-change = "selection handler ()" & gt; & Lt; Option value = "" & gt; Anywhere & lt; / Options & gt; & Lt; Option value = "{{prsn}}" ng-repeat = "PSN in individuals" & gt; {{Prsn.name}} & lt; / Options & gt; & Lt; / Select & gt; $ Scope.selectHandler = function () {if ($ scope.person == '') {console.log ("route / / home"); // root with location location.path}}  

is working for the demo.


Comments

Popular posts from this blog

c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

c# - WPF Expander overlay used in ItemsControl -

android - how to get distance of 2 beacons and make a condtion base on that distance -