{"action":"created","issue":{"url":"https://api.github.com/repos/angular/angular/issues/23382","repository_url":"https://api.github.com/repos/angular/angular","labels_url":"https://api.github.com/repos/angular/angular/issues/23382/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular/issues/23382/comments","events_url":"https://api.github.com/repos/angular/angular/issues/23382/events","html_url":"https://github.com/angular/angular/issues/23382","id":314322036,"number":23382,"title":"[Feature request] Compile time expressions in template","user":{"login":"bvdmitri","id":6557701,"avatar_url":"https://avatars0.githubusercontent.com/u/6557701?v=4","gravatar_id":"","url":"https://api.github.com/users/bvdmitri","html_url":"https://github.com/bvdmitri","followers_url":"https://api.github.com/users/bvdmitri/followers","following_url":"https://api.github.com/users/bvdmitri/following{/other_user}","gists_url":"https://api.github.com/users/bvdmitri/gists{/gist_id}","starred_url":"https://api.github.com/users/bvdmitri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bvdmitri/subscriptions","organizations_url":"https://api.github.com/users/bvdmitri/orgs","repos_url":"https://api.github.com/users/bvdmitri/repos","events_url":"https://api.github.com/users/bvdmitri/events{/privacy}","received_events_url":"https://api.github.com/users/bvdmitri/received_events","type":"User","site_admin":false},"labels":[{"id":375501288,"url":"https://api.github.com/repos/angular/angular/labels/comp:%20core%20&%20compiler","name":"comp: core & compiler","color":"c7def8","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/angular/angular/milestones/83","html_url":"https://github.com/angular/angular/milestone/83","labels_url":"https://api.github.com/repos/angular/angular/milestones/83/labels","id":3143880,"number":83,"title":"needsTriage","description":"Milestone for all issues that haven't been triaged yet","creator":{"login":"ocombe","id":265378,"avatar_url":"https://avatars0.githubusercontent.com/u/265378?v=4","gravatar_id":"","url":"https://api.github.com/users/ocombe","html_url":"https://github.com/ocombe","followers_url":"https://api.github.com/users/ocombe/followers","following_url":"https://api.github.com/users/ocombe/following{/other_user}","gists_url":"https://api.github.com/users/ocombe/gists{/gist_id}","starred_url":"https://api.github.com/users/ocombe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ocombe/subscriptions","organizations_url":"https://api.github.com/users/ocombe/orgs","repos_url":"https://api.github.com/users/ocombe/repos","events_url":"https://api.github.com/users/ocombe/events{/privacy}","received_events_url":"https://api.github.com/users/ocombe/received_events","type":"User","site_admin":false},"open_issues":407,"closed_issues":255,"state":"open","created_at":"2018-02-26T14:22:18Z","updated_at":"2018-04-23T04:55:46Z","due_on":null,"closed_at":null},"comments":35,"created_at":"2018-04-14T11:33:41Z","updated_at":"2018-04-23T05:38:41Z","closed_at":"2018-04-23T04:55:46Z","author_association":"NONE","body":"<!--\r\nPLEASE HELP US PROCESS GITHUB ISSUES FASTER BY PROVIDING THE FOLLOWING INFORMATION.\r\n\r\nISSUES MISSING IMPORTANT INFORMATION MAY BE CLOSED WITHOUT INVESTIGATION.\r\n-->\r\n\r\n## I'm submitting a...\r\n<!-- Check one of the following options with \"x\" -->\r\n<pre><code>\r\n[ ] Regression (a behavior that used to work and stopped working in a new release)\r\n[ ] Bug report  <!-- Please search GitHub for a similar issue or PR before submitting -->\r\n[ ] Performance issue\r\n[x] Feature request\r\n[ ] Documentation issue or request\r\n[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\r\n[ ] Other... Please describe:\r\n</code></pre>\r\n\r\n## Current behavior\r\n<!-- Describe how the issue manifests. -->\r\n\r\nAs i can see angular template syntax is not providing a way to declare a constant compile time expressions in template. Any `{{ expression }}`  should be invoked in runtime in order to be tracked for changing. But it might be useful to declare an expression which won't be changed, but still referenc it from component's class. \r\n\r\n## What is the motivation / use case for changing the behavior?\r\n<!-- Describe the motivation or the concrete use case. -->\r\n\r\nLet me show you example of use case.\r\n\r\n```\r\nexport { globalConstMessages } from './utils/messages'\r\n\r\n@Component({\r\n    selector: 'app',\r\n    template: '<p>{{ text }}</p>' // or may be some other syntax something like <p>@text</p>\r\n})\r\nexport class MyComponent {\r\n    public readonly text: string = globalConstMessages.someText; // <-- 'Hello world' for example\r\n}\r\n```\r\n\r\nThere is no way to transform this template at **compile-time** into\r\n```\r\n@Component({\r\n    selector: 'app',\r\n    template: '<p>Hello world</p>'\r\n})\r\nexport class MyComponent {\r\n    // empty here, no variable at all\r\n}\r\n```\r\nIn this case we will be able to avoid unnessesary change detections in run-time. It will be usefull in cases where we need to reuse some text messages across application, and it will be much easier to maintain this messages in one file and then only reference them as constant compile-time expression in other templates.\r\n\r\nAlso it will be a nice feature if we will be able to declare an @Input's variable of other component's as a constant compile-time expressions, but i think it will be much harder to implement.\r\n\r\nFor example\r\n```\r\n@Component({\r\n    selector: 'tooltip',\r\n    template: '<p>{{ text}}</p>'\r\n})\r\nexport class TooltipComponent {\r\n    @Input('text')\r\n    public text: string;\r\n}\r\n```\r\n\r\n```\r\n@Component({\r\n    selector: 'app',\r\n    template: '<tooltip [text]=\"constantText\"></tooltip>'\r\n})\r\nexport class MyComponent {\r\n    public readonly constantText: string = 'Hello world!';\r\n}\r\n```\r\n\r\nand it should be transformed at **compile-time** into \r\n\r\n```\r\n@Component({\r\n    selector: 'app',\r\n    template: '<p>Hello world</p>'\r\n})\r\nexport class MyComponent {}\r\n```\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/angular/angular/issues/comments/383460008","html_url":"https://github.com/angular/angular/issues/23382#issuecomment-383460008","issue_url":"https://api.github.com/repos/angular/angular/issues/23382","id":383460008,"user":{"login":"trotyl","id":6059170,"avatar_url":"https://avatars0.githubusercontent.com/u/6059170?v=4","gravatar_id":"","url":"https://api.github.com/users/trotyl","html_url":"https://github.com/trotyl","followers_url":"https://api.github.com/users/trotyl/followers","following_url":"https://api.github.com/users/trotyl/following{/other_user}","gists_url":"https://api.github.com/users/trotyl/gists{/gist_id}","starred_url":"https://api.github.com/users/trotyl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trotyl/subscriptions","organizations_url":"https://api.github.com/users/trotyl/orgs","repos_url":"https://api.github.com/users/trotyl/repos","events_url":"https://api.github.com/users/trotyl/events{/privacy}","received_events_url":"https://api.github.com/users/trotyl/received_events","type":"User","site_admin":false},"created_at":"2018-04-23T05:38:41Z","updated_at":"2018-04-23T05:38:41Z","author_association":"CONTRIBUTOR","body":"@robwormald The constant folding in AOT only happens in the **Metadata Collector**, not the **Template Compiler**, they are different cases."}}
{"actor":{"display_login":"trotyl"}}