I've found this answer here: https://stackoverflow.com/a/28357122/5459561
It works perfectly on Plunker, but when I implement it in my project, it doesn't work.
My HTML:
<div ng-controller="PolicyController as policy">
<select multiple ng-model="proto" ng-init="proto=policy.protocols[0]"
ng-options="protocol for protocol in policy.protocols"></select>
<select multiple ng-model="fc" ng-options="function.code for function in
policy.functions | filter:{protocol:proto}"></select>
</div>
My JS:
app.controller('PolicyController', ['$http', function($http){
var policy = this;
policy.functions = [{"code": 1, "protocol": "A"},{"code": 2, "protocol": "A"},{"code": 3, "protocol": "B"},{"code": 4, "protocol": "C"}];
policy.protocols = ["A", "B", "C"];
Now the problem is when I click to change the current selected protocol, the codes disappear. But when I first initialize the page, I can see the codes for protocol A, which means the 'ng-init' is working properly.
NOTE: It does work in plunker as shown in the linked answer, but not in my project. I'm using angular V1.5.0, and the Plunker used 1.1.5. Though I don't believe it should make a difference.
Any ideas?